iphone - 当前位置的注释

标签 iphone objective-c ios

我正在做一个项目,我在其中添加了一个按钮,按下它应该会带我到我在 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];
  }
}

这在模拟器上运行良好,您可以在图像中看到它,

on top is the button on pressing which i get the location statically passed on second loop but on iPhone it won't works

但是当我尝试在 iPhone 上测试它时,它崩溃了。任何人都可以指出可能的原因是什么?谢谢

最佳答案

首先我想告诉你,你无法从模拟器中获取当前位置。在您的代码中,您只是使用了静态纬度。长。对于设备,我分享了一个链接,只需检查即可。

http://pastebin.com/Vv1wvyBh

这可能对你有帮助:)

谢谢。

关于iphone - 当前位置的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550777/

相关文章:

iOS:放大/缩小动画以显示 UIView

iphone - 如何使用 xcode 4 运行phonegap?

iphone - 文本编辑后更新时 UITableView 崩溃

ios - 如何在 Cocos2D 3.x 中为 CCSprite 制作动画?

ios - 如何将 "today"(NSDate) 与格式化字符串日期 (dd/MM/yyyy) 进行比较?

ios - 更改 rootViewController 导致奇怪的行为

iphone - 如何禁用 UINavigationBarItem?

ios - 将 AVPlayerLayer 添加为当前 View 的子层在 iPhone 5 上不起作用

ios - 聚合函数如何处理 Core Data 中的一对多关系

objective-c - UISwitch 在 UIScrollView 中没有响应