Hi in my application I'm fetching the the current location using Google IOS SDK know i want to store the current location Longitude and Latitude NSString please tell me how to do it.
My current location fetching code.
- (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];
}
I'm using the above code to get the current location please tell how to store the latitude and langitude in NSString .
Thanks.
- (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)
}
}