Latitude, longitude from mapView.userLocation

I have the following code to get userLocation in my application:

mapView.showsUserLocation=TRUE;
    mapView.userLocation.title=@"Aktuelle Position";

That is, in viewDidLoad();

But how can I get latitude and longitude from userLocationin the following method?

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{

    Koordinate *user = mapView.userLocation;
    Koordinate *cord1 = [eventPoints objectAtIndex:2];
    CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:cord1.latitude longitude:cord1.longtitude];

    Koordinate *cord2 = [eventPoints objectAtIndex:3];
    CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:cord2.latitude longitude:cord2.longtitude];

    double distance = [loc1 getDistanceFrom:loc2] / 1000;

    NSLog(@"Distanz:", distance);
}
+3
source share
2 answers
-(void)locationManager:(CLLocationManager *)manager
  didUpdateToLocation:(CLLocation *)newLocation
      fromLocation:(CLLocation *)oldLocation
{
    float lat = newLocation.coordinate.latitude; 
    float lon = newLocation.coordinate.longitude;
}
+1
source

Here is what worked for me.

yourMapView.userLocation.location.coordinate.latitude;
yourMapView.userLocation.location.coordinate.longitude;
0
source

Source: https://habr.com/ru/post/1734218/


All Articles