Oomph / MacMapKit

MapKit Framework for the Mac
BSD 3-Clause "New" or "Revised" License
256 stars 43 forks source link

Cannot add annotation before -[MKMapViewDelegate mapViewWillStartLoadingMap:] #7

Open stefanfisk opened 12 years ago

stefanfisk commented 12 years ago

If -[MKMapView addAnnotation:] is called before -[MKMapViewDelegate mapViewWillStartLoadingMap:] it fails with the following message: "Error creating internal representation of annotation view for annotation: <MKPointAnnotation: 0x7fc514969060> <0.000000, 0.000000> Pin Title - (null)".

Also, -[MKMapView setCenterCoordinate:] seems to have no effect until after -[MKMapViewDelegate mapViewWillStartLoadingMap:].

This is not consistent with MKMapView on iOS. I'd assume that the root cause is related to the web view not having loaded properly before -[MKMapViewDelegate mapViewWillStartLoadingMap:], but I have not investigated it further as it is fairly easy to work around.

rickfillion commented 12 years ago

You're right.

The reason for this is that the objc code routes those calls to javascript, and before you get that delegate call, the JS isn't ready to accept requests yet (things are in the process of loading). So the fix would be to have a way to queue those calls up until things are ready, then when it's ready, execute everything on the queue again.

LucasDeVil commented 12 years ago

This is quite an annoying behaviour. I'm loading the locations at application startup and post a notification that there is new data. This happens way before -mapViewWillStartLoadingMap: and I have no clue how I could queue this event. The notification is posted in awakeFromNib.

In addition -mapViewWillStartLoadingMap: isn't called (using 10.7.4).

rickfillion commented 12 years ago

Waiting for -[MKMapViewDelegate mapViewDidFinishLoadingMap:] is likely the better fix.

I agree that it's annoying behaviour, but I'm I've got zero cycles to throw at this for the time being. You can either work around it, or attempt to fix it yourself.

I just tested here and mapViewDidFinishLoadingMap does get called on 10.7.4, whereas willStartLoadingMap seems to not be called (I'd have to look into that).

LucasDeVil commented 12 years ago

Thank you for this suggestion. :)