How to recenter map in iPhone app on zoom in/out using MKMapView

北战南征 提交于 2019-12-24 22:19:39

问题


I am developing an iPhone application in which I need to show an image at a specific Latitude & Longitude on a Map. The requirement is - Even if the user zooms in or out on this map screen, the map control should automatically center itself after the zoom, to the same Lat & Long. I am using MKMapView.

I have tried to go through all available documentation. However, I could not come across any callback or other method that will allow me to achieve the objective.

One alternative is to handle touch events. However, I find that as a very complicated solution. And I hope that a simpler alternative exists. Any ideas on the above?

Can you please help? Any example will be appreciated.


回答1:


Implement MKMapViewDelegate and then try this:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    [mapView setCenterCoordinate:locationManager.coordinate animated:NO];
}

Replace locationManager with whatever the name of your CLLocationManager is.



来源:https://stackoverflow.com/questions/3903913/how-to-recenter-map-on-zoom-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!