Map Matching Resource Usage

Hi,

Could anyone give me any pointers on how to use the MapMatchingResource.java file to implement the map matching functionality in my own application? Some questions I have are:

  1. in the MapMatchingResource class, what are profileResolver and trMap? Also, how do I pass graphhopper as an instantiation parameter?
  2. What method do I call on my MapMatchingResource object in order to perform the map matching? How do I pass the gpx files?

I would really, really appreciate any help or even any sample code snippets anyone is willing to share.

Do you want to do map matching in a server or desktop application? MapMatchingResource implements a server endpoint to perform map matching, but for desktop usage you should probably use the MapMatching class directly or take a look at MatchCommand. See also the documentation here: https://github.com/graphhopper/graphhopper/tree/master/map-matching.

ProfileResolver is just used for legacy reasons, you most likely do not need it. It is used to determine the profile for requests that only specify a weighting and vehicle. trMap is used for translations. The graphHopper object can be passed to the MapMatchingResource constructor, but this is done automatically via Dropwizard’s dependency injection for the GH server.

You can just call the match method, but again usually this happens implicitly when a request is sent to the GH server’s /match endpoint. Again, take a look at MatchCommand to see how gpx files can be handled.

Thank you very much for the reply!
I am aiming to do the map matching in a desktop application. So do I understand it correctly: I can instantiate a MapMatching object and then call the match command on it? What does the parameter ‘PMap hints’ specify? And what is the Observation List that I have to pass to the match function?

Take a look at MatchCommand and it should be clear how to use the MapMatching class in a desktop application. The observation list is just a list of GPS coordinates and you can also find code that converts gpx data to such a list of points in MatchCommand. hints can be all kind of parameters most of which you probably do not need (except profile). You need to check the source code to see what they do exactly.

Thank you so much, this already really helped! One more thing: what do I pass to the run() function of MatchCommand? The function signature is:

protected void run(Bootstrap bootstrap, Namespace args, GraphHopperServerConfiguration configuration)

What exactly are these three arguments?

Thank you so much again!

The run method is used by dropwizard so the match command can be used from the command line (as described in the map matching docs). If you want to run map matching in a desktop application you probably should not use the MatchCommand class directly, but rather just look at the code to see how the MapMatching class is used and then call the match method in your application in a similar fashion.

Powered by Discourse