如何获取用户当前位置

时间:2016-11-22 05:40:06

标签: ios objective-c google-maps

如何获取用户当前位置。我希望跟踪用户的速度,并希望在他移动到另一个地方时绘制路径。

1 个答案:

答案 0 :(得分:0)

您可以通过CLLocationManager获取用户当前位置:

添加以下代码获取ViewDidLoad:

CLLocationManager  *objLocationManager = [[CLLocationManager alloc] init];
objLocationManager.delegate = self;
objLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
[objLocationManager requestWhenInUseAuthorization];
[objLocationManager startUpdatingLocation];

以下是返回纬度和经度的委托:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
      CLLocation *currentLocation = locations; 
}