Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS additional calls to RouteCalculationFinishedCommand #61

Closed
CliffCawley opened this issue Apr 5, 2016 · 2 comments
Closed

iOS additional calls to RouteCalculationFinishedCommand #61

CliffCawley opened this issue Apr 5, 2016 · 2 comments
Labels

Comments

@CliffCawley
Copy link
Contributor

So I'm not 100% sure if this is a bug or if it's something you might need to document as a gotcha, but thought I'd make you aware as it seems to have caused some issues in my project:

I would calculate the route and receive my RouteCalculationFinishedCommand events, and I'd wait for the route calculation to be done:

if (Route.All(i => i.IsCalculated))
{
    MapView.FitToMapRegions(Route.Select(i => i.Bounds), true);
    CalculatingRoute = false;
}

CalculatingRoute is a property I was using to show a progress spinner to show the calculation was busy.

Then when the FitToMapRegions has run, the iOS map animates over to the region and when it's there another MapLoaded event comes through.

This in turn runs:

this.UpdateRoutes();

Which then again goes out and sends out all the RouteCalculationFinishedCommand.

In my code then for every RouteCalculationFinishedCommand, as the Route was already previously calculated, I was then calling FitToMapRegions every single time I got that RouteCalculationFinishedCommand. This then resulted in more calls to MapLoaded depending on race conditions.

I've now fixed this in my code by checking first to ensure I'm expecting that the route hasn't been calculated by using my CalculatingRoute property.

if (CalculatingRoute && Route.All(i => i.IsCalculated))
{
    MapView.FitToMapRegions(Route.Select(i => i.Bounds), true);
    CalculatingRoute = false;
}

@TorbenK I'll leave it up to you for the fix as I'm not sure which way you want to go about it :)

@CliffCawley
Copy link
Contributor Author

@TorbenK I was going to report a seperate bug but it's related to this same issue. That issue where I get multiple Routes added to _routes is related to this. It's difficult to reproduce because it's a thread race condition. With each multiple call of MapLoaded, it's calling into UpdateRoutes and then AddRoute which does a delayed _routes.Add when the directions have been calculated.

If the timing is right, _routes is cleared after the delayed _routes.Add are called, however sometimes the _routes.Add gets called after a previous UpdateRoutes call clears _routes and this is where I get the multiple routes added which later results in a crash on

var item = this._routes.SingleOrDefault(i => i.Value.Overlay.Equals(route));

Due to there being more than a single item.

I know you're short on time at the moment but if you let me know your thoughts about how you wanted to fix it, I could tackle this and put a pull request in.

A solution I've come up with is to create a pending list of MKDirections. When the routes list is cleared, this list is also cleared. When the CalculateDirections call returns, it checks to see if it's directions object is still in the list and if not, it just discards the results.

@TorbenK
Copy link
Owner

TorbenK commented Apr 8, 2016

The MapLoaded is simply wrong in iOS, or to be more exact, I should have read the iOS documentation. I simply was suspecting that this is called just once the map is loaded the first time, but it's called every time any action on the map was performed(like zoom, panning). This is a major issue, I would recommed you to fix it up in your fork, the Command and all the initialization should only be called the first time the map loaded.

TorbenK added a commit that referenced this issue Apr 29, 2016
      New: TKCustomMapPin is BindableObject
      New: All Commands also available as Event
      New: Possibility to set the anchor position of a pin(Alpha)

      Fixed: Issue with PinTinColor(iOS) #68
      Fixed: Issue with multiple calls to MapLoaded(iOS) #60,#61,#50
      Fixed: Issue with missing culture information when converting coordinates to string(Android) #55
      Fixed: Double tap no longer triggers MapClicked(iOS) #46
      Fixed: Bounds calculation after route calculation is now correct
      Fixed: Collection events getting unregistered properly
      Fixed: Issue when route gets removed from collection during calculation

      Minor bugfixes
@TorbenK TorbenK closed this as completed Apr 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants