如何在NSString IOS7中存储当前位置纬度和经度

时间:2014-06-07 07:41:24

标签: ios google-maps nsstring google-maps-sdk-ios

您好我的应用程序我使用Google IOS SDK获取当前位置知道我想存储当前位置经度和纬度NSString请告诉我该怎么做。

我当前的位置提取代码。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
      GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude
                                                        longitude:newLocation.coordinate.longitude
                                                             zoom:17.0];
      [googleMapView animateToCameraPosition:camera];

 }

我使用上面的代码获取当前位置,请告诉我如何在NSString中存储纬度和经度。

感谢。

1 个答案:

答案 0 :(得分:2)

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
[locationManager stopUpdatingLocation];

CLLocation *currentLocation = newLocation;

if (currentLocation != nil) {

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude
                                                    longitude:newLocation.coordinate.longitude
                                                         zoom:17.0];
  [googleMapView animateToCameraPosition:camera];

    NSString *getcurrlong = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
    NSString *getcurrlat = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];


}
}

Swift 3

 func locationManager(_ manager: CLLocationManager, didUpdateTo newLocation: CLLocation, from oldLocation: CLLocation) {
print("didUpdateToLocation: \(newLocation)")
locationManager.stopUpdatingLocation()
let currentLocation: CLLocation? = newLocation
if currentLocation != nil {
    let camera = GMSCameraPosition.camera(with: newLocation.coordinate.latitude, longitude: newLocation.coordinate.longitude, zoom: 17.0)
    googleMapView.animate(to: camera)
    var getcurrlong = String(format: "%.8f", currentLocation?.coordinate?.longitude)
    var getcurrlat = String(format: "%.8f", currentLocation?.coordinate?.latitude)
}
}