我有以下代码在我的应用上获取userLocation:
mapView.showsUserLocation=TRUE;
mapView.userLocation.title=@"Aktuelle Position";
那是viewDidLoad();
但是如何从userLocation
获取以下方法中的纬度和经度?
- (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);
}
答案 0 :(得分:0)
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
float lat = newLocation.coordinate.latitude;
float lon = newLocation.coordinate.longitude;
}
答案 1 :(得分:-1)
这对我有用。
yourMapView.userLocation.location.coordinate.latitude;
yourMapView.userLocation.location.coordinate.longitude;