我正在做一个项目,我在其中添加了一个按钮,按下它应该会带我到我在 map 上的当前位置,并且应该显示蓝色指示器来指示位置,这是代码:
-(IBAction)gotoLocation
{
if(curntloc)
{
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.0112872;
mapRegion.span.longitudeDelta = 0.0112872;
[self.mapView setRegion:mapRegion animated: YES];
}
else
{
curntloc = [[CLLocation alloc] initWithLatitude:21.192415 longitude:72.821159];
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.0112872;
mapRegion.span.longitudeDelta = 0.0112872;
[self.mapView setRegion:mapRegion animated: YES];
}
}
这在模拟器上运行良好,您可以在图像中看到它,
但是当我尝试在 iPhone 上测试它时,它崩溃了。任何人都可以指出可能的原因是什么?谢谢
最佳答案
首先我想告诉你,你无法从模拟器中获取当前位置。在您的代码中,您只是使用了静态纬度。长。对于设备,我分享了一个链接,只需检查即可。
这可能对你有帮助:)
谢谢。
关于iphone - 当前位置的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550777/