2011-06-01 60 views

回答

1

看看CLLocationManager。您可以简单地创建一个实例,将您的控制器设置为委派,启动实例以获取您的位置,并在您的委托方法中处理结果,即可访问坐标。无需地图。

+0

嗨,马克....感谢您的快速答复.....你有代码示例,我可以看到?谢谢 – pithhelmet 2011-06-03 14:38:54

+0

其实,@ bensnider的例子就是你所需要的。您将该代码放入您的应用程序委托中。在'applicationDidFinishLaunching:'你可以调用'[self startUpdates]'。您必须填写'locationManager:didUpdateToLocation:fromLocation'的细节,但实质上您正在查找的信息位于该委托方法的'newLocation'参数中。 – 2011-06-03 14:58:04

1
- (void)startUpdates { 
    coreManager = [[CLLocationManager alloc] init]; 
    coreManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 
    coreManager.delegate = self; 
    [coreManager startUpdatingLocation]; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    // newLocation is location from gps... 
    // you'll need to stop coreManager updating when you have a good fix 
} 

有关详细信息,请参阅Apple docs

+0

明确地说,所有你需要的是什么在'newLocation' – theiOSDude 2011-06-01 15:51:53

+0

感谢您的代码块...我在哪里可以放置此代码块? – pithhelmet 2011-06-03 14:43:27

1

CLLocationManager是你必须按顺序检索当前的纬度/龙

下面是代码使用的接口:

locationManager = [[CLLocationManager alloc] init]; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
locationManager.distanceFilter = DISTANCE_FILTER_VALUE; 
locationManager.delegate = self; 
[locationManager startUpdatingLocation]; 
相关问题