itinero / routing-api

An API based on Itinero.
MIT License
13 stars 16 forks source link

Router.Resolve crashes - not sure what to do #21

Open gfmoore opened 2 years ago

gfmoore commented 2 years ago

My routing program has been running well, many thanks for a superb package.

However today I came across a crash. I am using .net Maui

Here is my code

  public double ItineroDistance(PostcodePosition pp1, PostcodePosition pp2)
  {
    // calculate a route.

    // snaps the given location to the nearest routable edge.
    var start = router.Resolve(profile, (float) pp1.Latitude, (float) pp1.Longitude);
    var end = router.Resolve(profile, (float) pp2.Latitude, (float) pp2.Longitude);

    var route = router.Calculate(profile, start, end);

    return route.TotalDistance; //(in meters)
  }

pp1.Latitude was 53.033809 pp1.Longitude was -2.151793 pp2.Latitude was 52.807553 pp2.Longitude was -1.740858 The profile is "car" I obtain these from UK Postcodes ST1 6SS and DE13 9RD https://api.postcodes.io/postcodes/

The exception Itinero.Exceptions.ResolveFailedException: 'Could not resolve point at [52.807552, -1.740858]. Probably too far from closest road or outside of the loaded network.'

On OpenStreetMap (which I'm using) image

On Google image

What would be the best way to handle this? Use a try catch? Then what would I do in the catch? I could just do a CrowFlies calc (I have some code for that) I suppose. Or is it a bug?

Thanks for any suggestions, advice, help. Gordon :)

gfmoore commented 2 years ago

Doing a try catch meant that the exception could be ignored (ok handled). Any other thoughts. I suspect something about the farm track/lane is not being recognised?