确认 CoronaSDK 中的位置访问

发布于 2024-12-17 11:15:21 字数 321 浏览 0 评论 0原文

有没有什么方法可以直接请求访问用户的位置,或者是否有某种事件侦听器可以在授予位置访问权限后通知我?我遇到了与将 MapView 对象与 Director 类一起使用相关的问题,我认为这取决于此。

我有一个辅助视图,其中包含 MapView 组件。当主管类切换到该视图时,我的 MapView 对象被实例化,并且我尝试获取用户的位置。我遇到的问题是,在我的测试设备(iPhone 4)上,尝试访问用户的位置是在他们授予我位置访问权限之前发生的,因此只有当他们离开该屏幕并稍后返回该屏幕时(实例化)再次在导演库中)我可以使用他们的位置。

这显然是不能令人满意的。

有什么帮助/建议吗?

Is there any way to directly request access to the user's location, or is there an event listener of some kind that will notify me once location access has been granted? I'm having a problem related to the use of the MapView object with the Director class and I think it hinges on this.

I have a secondary view with a MapView component in it. When the director class switches to that view, my MapView object is instantiated and I attempt to get the user's location. The problem I'm having is that on my test device (iPhone 4), the attempt to access the user's location takes place before they've granted me location access, so it's only when they leave that screen and later return to it (instantiating it again in the Director library) that I'm able to use their location.

This is obviously unsatisfactory.

Any help/advice?

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

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

发布评论

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

评论(1

望她远 2024-12-24 11:15:21

问题的解决方案很大程度上取决于您的代码。如果您想获得帮助,您应该明确地将相关代码位包含在您的 SO 问题中。

我将进行猜测并假设您的代码看起来与 MapView 示例类似:

http:// /developer.anscamobile.com/reference/index/nativenewmapview

如果是这种情况,问题就在于位置检索得很晚。

local function callMap()
        -- Fetch the user's current location
        -- Note: in XCode Simulator, the current location defaults to Apple headquarters in Cupertino, CA
        local currentLocation = myMap:getUserLocation()
        local currentLatitude = currentLocation.latitude
        local currentLongitude = currentLocation.longitude
        ...

您想要的是更早执行的代码。理想情况下,当应用程序启动时。用户将立即收到“此应用程序想要访问 GPS”消息,因此他们在看到地图视图之前将有更多时间“批准”。

您可以做的另一件事是使用缓存。将最新的已知位置存储在某处(配置文件或数据库,具体取决于您的设置)。当连接丢失或尚未恢复时,在地图上显示最后的已知位置。

The solution to your problem greatly depends on your code. You should definitively include the relevant code bits in your SO questions if you want to get help.

I'm going to make a guess and assume that your code looks similar to the MapView example:

http://developer.anscamobile.com/reference/index/nativenewmapview

If that's the case, the problem is that the location is retrieved very late.

local function callMap()
        -- Fetch the user's current location
        -- Note: in XCode Simulator, the current location defaults to Apple headquarters in Cupertino, CA
        local currentLocation = myMap:getUserLocation()
        local currentLatitude = currentLocation.latitude
        local currentLongitude = currentLocation.longitude
        ...

What you want is that code executed earlier. Ideally, when the application starts. The user will get the "this application wants access to the GPS" message right away, so they will have more time to "approve" before seeing the mapview.

Another thing you can do is using a cache. Store the latest known location somewhere (a config file or the database, depending on your setup). When the connection is lost, or not yet retrieved, show the last known location on the map.

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