Centering map against user's location

送分小仙女□ 提交于 2019-12-08 04:37:37

问题


I'd like to center a map (mapkit) against the user's location. I do the following in the simulator but only get a blue map with no content. What steps should I be taking?

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;

CLLocationCoordinate2D location;
location.latitude = mapView.userLocation.location.coordinate.latitude;
location.longitude = mapView.userLocation.location.coordinate.longitude;

region.span=span;
region.center=location;
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

The long/lat values from the above are:

location.latitude = 1.0256307104653269e-305
location.longitude = 1.2742349910917941e-313

--- EDIT ---
I found the answer to my follow up comment here: Mapkit UserLocation found event. Used with the answer below, that provides the solution.


回答1:


A blue map with no content usually means that you're somewhere in the ocean. Zoom out and check your coordinates, you're most likely off the coast of Africa at latitude 0.0 and longitude 0.0. Have you checked to see what values are in your latitude and longitude?

You could also try using -setCenterCoordinate: animated: with the userLocation center.



来源:https://stackoverflow.com/questions/2107142/centering-map-against-users-location

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