返回 Mapkit 用户位置坐标

发布于 2024-08-09 17:10:35 字数 159 浏览 2 评论 0原文

每当我尝试返回当前位置的纬度/经度坐标时,我的应用程序就会崩溃,并且没有任何错误解释...

NSLog(@"%@", mapView.userLocation.location.coordinate);

我正在等待手机也找到该位置...

whenever I try to return the lat/long coordinates for my current location, my application crashes with no explanation of the error...

NSLog(@"%@", mapView.userLocation.location.coordinate);

I am waiting until the phone finds the location as well...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

递刀给你 2024-08-16 17:10:35

mapView.userLocation.location.cooperative 是一个结构体,而 %@ 格式说明符需要一个对象。这将起作用:

NSLog(@"%f, %f", mapView.userLocation.location.coordinate.latitude,
                 mapView.userLocation.location.coordinate.longitude);

mapView.userLocation.location.coordinate is a struct while the %@ format specifier expects an object. This will work:

NSLog(@"%f, %f", mapView.userLocation.location.coordinate.latitude,
                 mapView.userLocation.location.coordinate.longitude);
贪恋 2024-08-16 17:10:35

由于某种原因,这对我不起作用。它带我到坐标 (0.0000, 0.0000)。下面是我的代码,如果您有机会查看一下。感谢您的帮助!

[mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    mapView.showsUserLocation=TRUE;

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };

    CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
    [mapView setCenterCoordinate:myCoord animated:YES];

    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self];

For some reason, this didn't work for me. It's taking me to the coordinates (0.0000, 0.0000). Below is my code if you have a chance to check it out. Thanks for the help!

[mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    mapView.showsUserLocation=TRUE;

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };

    CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
    [mapView setCenterCoordinate:myCoord animated:YES];

    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文