【问题标题】:userLocation: latitude/longitude return zero?userLocation:纬度/经度返回零?
【发布时间】:2011-03-11 20:58:49
【问题描述】:

我只是在看 mapKit 并决定制作一个快速按钮来显示我当前的位置,但是当我按下按钮时,我的纬度/经度总是显示为 [0.000000] [0.000000]。

mapView 已加载,因为我可以在按下按钮之前在模拟器上看到地图。以前我通过使用 coreLocation.framework 并使用 CLLocationManager 并以这种方式询问设备位置来完成此操作。我只是好奇为什么这种方式不能正常工作,我会更好地通过 CLLocationManager 这样做吗?

-(IBAction)findMePressed {
    MKUserLocation *myLocation = [myMapView userLocation];
    CLLocationCoordinate2D coord = [[myLocation location] coordinate];
    [myMapView setCenterCoordinate:coord animated:YES];
    NSLog(@"findMePressed ...[%f][%f]", coord.latitude, coord.longitude);
}

编辑:添加...

-(IBAction)findMePressed {
     MKUserLocation *myLocation = [myMapView userLocation];
     CLLocationCoordinate2D coord = [[myLocation location] coordinate];
     MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 350, 350);
     [myMapView setRegion:region animated:YES];
}

-(void)viewDidLoad {
    [super viewDidLoad];
    [myMapView setShowsUserLocation:YES];
}

加里。

【问题讨论】:

    标签: iphone objective-c cocoa-touch


    【解决方案1】:

    要么 userLocation 在地图上不可见(参见 userLocationVisible 属性),要么设置 myMapView 属性时出现问题并且它为 nil(即未在界面生成器中连接)

    【讨论】:

    • 嗨,Dean,userLocationVisible 是 [0],所以我想这就是问题所在。 myMapView 在 IB 中连接,因此它正确指向我的 iVar。
    • 我的地图显示库比蒂诺的方式就在显示屏的左侧。设置 showUserLocation 并创建区域符合我的预期,非常感谢。
    【解决方案2】:
    [...] 我可以在 模拟器上看到地图 [...]

    在设备上进行测试。默认情况下,在模拟器上,你返回的坐标是苹果的总部。参照。 doc.

    有关解决方法和有用实用程序的其他 SO 问题:Testing CoreLocation on iPhone Simulator

    【讨论】:

    • 你好纪尧姆,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多