3

I have the following code to get the userLocation on my app:

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

That is in the viewDidLoad();

But how can I get latitude and longtitude in from userLocation in 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);
}
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Marco
  • 461
  • 1
  • 10
  • 22
  • Here is a [similar question](http://stackoverflow.com/questions/1449486/iphone-current-user-location-coordinates-showing-as-0-0). – greg Feb 24 '10 at 14:00

2 Answers2

0
-(void)locationManager:(CLLocationManager *)manager
  didUpdateToLocation:(CLLocation *)newLocation
      fromLocation:(CLLocation *)oldLocation
{
    float lat = newLocation.coordinate.latitude; 
    float lon = newLocation.coordinate.longitude;
}
Luke
  • 11,426
  • 43
  • 60
  • 69
Steven Marlowe
  • 230
  • 2
  • 16
-1

Here's what worked for me.

yourMapView.userLocation.location.coordinate.latitude;
yourMapView.userLocation.location.coordinate.longitude;
Danny
  • 3,670
  • 12
  • 36
  • 45