根据用户位置将地图居中
我想将地图(mapkit)以用户的位置为中心。我在模拟器中执行以下操作,但只得到一张没有内容的蓝色地图。我应该采取什么步骤?
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];
上面的经度/纬度值为:
location.latitude = 1.0256307104653269e-305
位置.经度 = 1.2742349910917941e-313
--- 编辑 ---
我在这里找到了后续评论的答案:Mapkit UserLocation 发现事件。与下面的答案一起使用,即可提供解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有内容的蓝色地图通常意味着您位于海洋中的某个地方。缩小并检查您的坐标,您很可能位于非洲海岸的纬度 0.0 和经度 0.0 处。您是否检查过您的纬度和经度的值是什么?
您还可以尝试将
-setCenterCooperative:animated:
与userLocation
中心一起使用。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 theuserLocation
center.