【问题标题】:Centering map against user's location根据用户位置居中地图
【发布时间】:2011-01-07 14:33:52
【问题描述】:

我想根据用户的位置将地图(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];

上面的 long/lat 值是:

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

--- 编辑 ---
我在这里找到了我后续评论的答案:Mapkit UserLocation found event。与下面的答案一起使用,提供了解决方案。

【问题讨论】:

    标签: iphone cocoa-touch iphone-sdk-3.0 mapkit


    【解决方案1】:

    没有内容的蓝色地图通常意味着您在海洋中的某个地方。缩小并检查您的坐标,您很可能位于非洲海岸 0.0 纬度和 0.0 经度处。您是否检查过您的纬度和经度中的值?

    您也可以尝试将-setCenterCoordinate: animated:userLocation 中心一起使用。

    【讨论】:

    • 我已更新问题以反映您的问题的一些答案。我也在做这个 [self.mapView setCenterCoordinate:self.mapView.userLocation.location.coordinate] 但我还在大西洋。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多