gpt4 book ai didi

ios - 如何从 iOS 中的 mapKit 获取纬度、经度?

转载 作者:行者123 更新时间:2023-12-01 18:00:06 26 4
gpt4 key购买 nike

我已将 mapkit 框架集成到我的项目中,一切正常。我只是在 map 中显示用户的当前位置,如下所示:

mapView.delegate = self;
mapView.showsUserLocation = YES;
MKUserLocation *userLocation = mapView.userLocation;
//numbers show map zoom. 500,500 = map stretches 500 meters to the North and the South of current location
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance (userLocation.location.coordinate,1000,1000);
[mapView setRegion:region animated:NO];

问题是我需要将当前位置的纬度和经度存储到 2 个变量中,但是这些值存储在哪里?

我试图打印以下内容,但它给了我 0.000。
NSLog(@"Latitude: %f" , mapView.userLocation.coordinate.latitude);
NSLog(@"Longitude: %f" , mapView.userLocation.coordinate.latitude);

最佳答案

实现这个委托(delegate)方法:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

基本上,一旦确定了用户的位置,MapView 就会调用这个位置。如果您查看 用户位置在飞行中,不能保证。

您可以在 中找到其余的委托(delegate)方法。 MKMapViewDelegate 协议(protocol)引用

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intf/MKMapViewDelegate

关于ios - 如何从 iOS 中的 mapKit 获取纬度、经度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11209848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com