I'm working on a new feature for my Mac application and it has to do with maps. As an example, let's use iPhoto's "Places".
iPhoto uses Google Maps to show the location of various photos with red pins. Now when I click onto one of those pins, the application itself - iPhoto - reacts to that click, not the WebView / the map. So when I click onto a pin, the view changes and it shows all photos in that location. Not on a map, but in a different screen within iPhoto. So I assume iPhoto gets some sort of callback from the JavaScript / Map so that it can change the view.
This is what I am开发者_运维百科 trying to achieve. Getting a callback from Google Maps back into my Objective-C / Cocoa code so I can change something inside my application, not the Map itself, depending on the marker the user has clicked on.
Thank you for any help, Kind regards,
Matthias
With UIWebView, I don't think there is a direct way to get a callback. One crude way would be to have a NSTimer periodically check the state/value of a javascript variable in the page by calling stringByEvaluatingJavaScriptFromString. Based on the value, the objective c code can do something. However, I don't recommend this.
It might be better to use an MKMapView instead which will give you easier, more direct access to the map (although MKMapView doesn't have all the features of the full Google Maps). I haven't tested this but this article shows a way to detect when a MKAnnotation pin is selected.
精彩评论