开发者

Mapkit lat- and longitude of current location

开发者 https://www.devze.com 2023-02-20 12:50 出处:网络
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.

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

精彩评论

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

关注公众号