【问题标题】:How to store the current location Latitude and Longitude in NSString IOS7如何在 NSString IOS7 中存储当前位置的经纬度
【发布时间】:2014-06-07 07:41:23
【问题描述】:

您好,在我的应用程序中,我正在使用 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 中。

谢谢。

【问题讨论】:

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


    【解决方案1】:
    - (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];
    
    
    }
    }
    

    斯威夫特 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)
    }
    }
    

    【讨论】:

    • 在 swift 3 中我使用了 didUpdateLocations 而不是 didUpdateToLocation
    • 你能告诉我这个方法什么时候被调用,即在进入选定页面时或当用户移动到另一个位置时?
    • 在此处进入所选页面称为
    • 它在 swift 3 中给出错误,无法覆盖已标记为不可用的“locationmanager”:从 iOS 7 及更早版本开始弃用的 API 在 Swift 中不可用
    • 在这个地方使用func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2011-08-18
    • 1970-01-01
    相关资源
    最近更新 更多