根据用户的位置居中地图 [英] Centering map against user's location
问题描述
我想将地图(mapkit)与用户的位置对齐。我在模拟器中做以下,但只得到一个没有内容的蓝色地图。我应该采取什么步骤?
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];
上述的long / lat值为:
The long/lat values from the above are:
location.latitude = 1.0256307104653269e-305
location.longitude = 1.2742349910917941e-313
location.latitude = 1.0256307104653269e-305
location.longitude = 1.2742349910917941e-313
--- EDIT --- < br>
我在这里找到我的后续评论的答案: Mapkit UserLocation found事件。与下面的答案一起使用,提供了解决方案。
--- EDIT ---
I found the answer to my follow up comment here: Mapkit UserLocation found event. Used with the answer below, that provides the solution.
推荐答案
没有内容的蓝色地图通常意味着你在某个地方海洋。缩小并检查您的坐标,你很可能离开非洲海岸在纬度0.0和经度0.0。
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?
您也可以尝试使用 -setCenterCoordinate:animated:
与 userLocation
中心。
You could also try using -setCenterCoordinate: animated:
with the userLocation
center.
这篇关于根据用户的位置居中地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!