允许应用程序使用当前位置后,mkmapview.userlocation 属性设置为 0,0

发布于 2024-08-14 12:28:26 字数 474 浏览 3 评论 0原文

用户第一次尝试使用当前位置时,map.userslocation 属性的坐标为 0,0。下次我加载包含地图的视图时,始终会找到用户位置。

我在 viewDidLoad 上将 map.showsUserLocation 属性设置为 YES,当地图加载到屏幕上时,蓝点就在那里,但是当我尝试使用 map.userlocation.coorinate 获取坐标时,它们是 0,0。

程序流程如下 -(无效)viewDidLoad: 1) 将 showUserLocation 设置为 YES 2) 设置一个计时器,在 6 秒后调用一个方法,从 map.userLocation 属性中获取用户位置

-(void) getUsersLocation 1)打印出用户位置

这个过程在我第一次加载视图后效果很好,但是第一次加载视图并且用户必须授予使用其位置的权限时坐标会返回0,0

任何人都知道为什么会发生这种情况以及我该如何解决它?

谢谢!

On the first time the user tries to use the current location the map.userslocation property has coordinates of 0,0. The next time I load the view containing the map the users location is always found.

I am setting the map.showsUserLocation property to YES on viewDidLoad and when the map loads on the screen the blue dot is there but when I try to get the coordinates with map.userlocation.coorinate they are 0,0.

The program flow goes
-(void) viewDidLoad:
1) set showUserLocation to YES
2) Set a timer to call a method 6 seconds later that grabs the users location from the map.userLocation property

-(void) getUsersLocation
1) print out the users location

This process works great after the first time I load the view, but the first time the view is laoded and the user has to grant permission to use their location the coordinates come back 0,0

Anybody have any idea why this happens and how I can work around it?

Thanks!

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

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

发布评论

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

评论(2

预谋 2024-08-21 12:28:26

您应该实现 CLLocationManagerDelegate 并注意何时调用

locationManager:didUpdateToLocation:fromLocation:

来为您提供第一次位置更新,而不是任意等待六秒钟,这可能需要更多或更少的时间。

rather than arbitrarily waiting six seconds, you should be implementing CLLocationManagerDelegate and noticing when

locationManager:didUpdateToLocation:fromLocation:

is called to give you the first location update, which might take more or less time than that.

春庭雪 2024-08-21 12:28:26

David 是对的,但我注意到有时确实会使用位置 0,0 调用该方法。您应该忽略任何此类呼叫,除非您认为您的应用程序可能在非洲西海岸附近的海域使用。

David is right, but I've noticed that I do sometimes get that method called with a location of 0,0. You should ignore any such calls, unless you think your app may be being used in the sea off the west coast of Africa.

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