【问题标题】:How do I get the users location latitude and longitude?如何获取用户位置的纬度和经度?
【发布时间】:2010-06-17 22:10:06
【问题描述】:

我需要在 mainViewController 中的这个方法中访问用户位置

-(void)loadAnnotations{
[mapView removeAnnotations:mapView.annotations];

CLLocationCoordinate2D workingCoordinate;
workingCoordinate.latitude= //here i need the users latitude
workingCoordinate.longitude= //here i need the users longitude
NSLog(@" this is %@", workingCoordinate.latitude);
iProspectLiteAnnotation *tempMine = [[iProspectLiteAnnotation alloc] initWithCoordinate:workingCoordinate];
[tempMine setTitle:@"Present Location"];
[tempMine setAnnotationType:iProspectLiteAnnotationTypeUser];
[mapView addAnnotation:tempMine];
}

但是 mainViewController 已经设置为

<fipsideViewControllerDelegate>

我应该在头文件和实现文件中添加什么来轮询位置管理器以获取用户当前的经纬度?

【问题讨论】:

    标签: objective-c iphone-sdk-3.0 core-location


    【解决方案1】:

    在您的另一个问题中,我已经告诉您如何获取位置,所以:

    -[CLLocation coordinate]

    在发布问题之前查看文档不会有什么坏处...

    【讨论】:

    • 所以我只需将其输入到 loadAnnotations 方法中?我查看了文档,但这就像大海捞针一样。这么多不必要的东西,都将locationManager委托设置为self,我不能这样做,因为该类设置为委托flipsideViewController
    • 哦,哇,我现在感觉智障了,哈哈。对语法的简单误解。
    • 然而,现在程序总是在此处的某个地方崩溃:CLLocation *location = [locationManager location]; [mapView removeAnnotations:mapView.annotations]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; CLLocationCoordinate2D workingCoordinate = [位置坐标]; NSLog(@" 这是 %@", workingCoordinate.latitude);
    猜你喜欢
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    相关资源
    最近更新 更多