开发者

Mapkit lat- and longitude of current location

I imagine its pretty simple, but I wont find it.

I want to show the longitude und latitude of the current user position in two textfields. One for each value.

But it defenatly wont work.

I thought it will be easy with 开发者_如何转开发one of the following values... But there are so many possibilitys of lon and lat...

mapView.userLocation.coordinate.latitude
mapView.userLocation.coordinate.latitude

mapView.userLocation.location.coordinate.latitude
mapView.userLocation.location.coordinate.longitude

Does anyone know which combination I need to take to simply get the long and lat value?

Thank you in advance from germany


The userLocation may not yet be available in viewDidLoad if that is also where the map view itself is being initialized.

A better place is in the didUpdateUserLocation delegate method:

- (void)mapView:(MKMapView *)mapView 
            didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"userLocation = %f,%f", mapView.userLocation.coordinate.latitude, 
                                  mapView.userLocation.coordinate.longitude);
}

Also make sure that:

  • map view's showsUserLocation is checked or set to YES
  • map view's delegate is set
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜