使用gomobile访问地理位置数据 [英] Access geolocation data using gomobile

查看:58
本文介绍了使用gomobile访问地理位置数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用本地 gomobile 应用程序访问手机的地理位置吗?

Can I access the phone's geolocation using a native gomobile application?

我已经在此处中看到了对传感器数据的实验性支持,但是没有关于设备的实际纬度和经度.

I have seen experimental support for sensor data here, but nothing about the actual latitude, longitude of the device.

我没有应用开发方面的经验,目前正在学习Go.

I have no prior experience in app development, and I am learning Go at the moment.

推荐答案

AFAIK尚无现成的解决方案,可以以独立于平台的方式访问Android和iOS上的位置.但是从理论上讲,您可以使用 gomobile 工具制作单独的程序包,以为每个平台生成绑定.

AFAIK there is no ready solution yet to access location on both Android and iOS in a platform independent way. But in theory you could make separate packages using the gomobile tool to generate bindings for each platform.

例如,在Android上,您将使用类似以下内容:

For example on Android you would use something like:

import "Java/android/content/Context"
import "Java/android/location/LocationManager"

locationManager := ctx.GetSystemService(Context.LOCATION_SERVICE)
// nil check omitted.
location := locationManager.GetLastKnownLocation(LocationManager.GPS_PROVIDER)
// nil check omitted.
lat := location.GetLatitude()
lng := location.GetLongitude()

其中 ctx 是您在其生命周期回调之一中收到的上下文(活动,服务等).

Where ctx is the context (an activity, service, etc.) that you receive in one of their lifecycle callbacks.

您还可以使用其他提供程序(网络,融合).

Also you can use other providers (network, fused).

这篇关于使用gomobile访问地理位置数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆