gpt4 book ai didi

ios - IOS7如何在NSString中存储当前位置的经纬度

转载 作者:行者123 更新时间:2023-11-28 22:05:38 27 4
gpt4 key购买 nike

您好,在我的应用程序中,我正在使用 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 中存储纬度和经度。

谢谢。

最佳答案

- (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)
}
}

关于ios - IOS7如何在NSString中存储当前位置的经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24094981/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com