ios - mapItemForCurrentLocation 找不到我的当前位置

标签 ios

我正在 ios 中的 mapkit 上工作,我必须从当前位置追踪我的路线。 现在,我已经使用模拟器(调试->位置->自定义位置)分配了我当前的位置,即纬度和经度,但是当我尝试追踪我的源时,我得到的源位置为零,因此我无法获得路线。

[directionsRequest setSource:[MKMapItem mapItemForCurrentLocation]];

谁能为我的问题提出可能的解决方案

代码

MKDirectionsRequest *directionsRequest = [[MKDirectionsRequest alloc] init];

MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:thePlacemark];

[directionsRequest setSource:[MKMapItem mapItemForCurrentLocation]];

[directionsRequest setDestination:[[MKMapItem alloc] initWithPlacemark:placemark]];

directionsRequest.transportType = MKDirectionsTransportTypeAutomobile;

MKDirections *directions = [[MKDirections alloc] initWithRequest:directionsRequest];

最佳答案

如果您使用的是 MapView,那么有一种委托(delegate)方法可以让您在不使用 CLLocationManager 的情况下获取当前位置。

 -(void)viewDidLoad
  {
    mapView.delegate=self;
  }   

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

{
   `enter code here`  //Here MKUserLocation will give you current Location and every time will method will call when the location is change...'

}

如果你只想要用户位置然后使用

 MKUserLocation *userlocation=mapView.userlocation

关于ios - mapItemForCurrentLocation 找不到我的当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22059112/

相关文章:

ios - 如何在 Swift 中终止(不是 segue)一个 View

ios - 回溯 IOS 使用 In-App Purchase IOS 支付的收据信息

ios - 在 iOS 中使用元数据保存 RGBA 图像

iOS AVFoundation - 以 60 fps 的速度将视频转换为图像

ios - 有时在 CLI 上运行 xcode 测试会返回 "manager not ready"

objective-c - 如何清除ipad中的webview缓存

ios - 自引用快速关闭

ios - 如何在 Swift 中更改 CDMarkdownKit 中的超链接颜色?

ios - 为什么转换后的 UIView 会与层次结构中更高层的其他 View 重叠?

ios - 从一点到另一点的弯曲箭头