开发者

Centering map against user's location

开发者 https://www.devze.com 2022-12-17 09:57 出处:网络
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?

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: 开发者_如何学JAVAMapkit UserLocation found event. Used with the answer below, that provides the solution.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消