Just simple as that.I dont want to find new coordinates every 10 minutes or meters.I just want to click a button and get my coordinates for this exact moment/place where i am.Every tutorial i've seen its old.New android versions require permissions to use GPS or Network.I am trying to implement those but nothing seems to work. Any solutions? Thanks in advance
就这么简单。我不想每隔10分钟或米找到新的坐标。我只想点击一个按钮,获取我在这个确切时刻/地点的坐标。每个教程我都看过它的旧。新的android版本需要使用GPS或Network的权限。我正在尝试实现这些但似乎没有任何工作。有解决方案?提前致谢
1 个解决方案
#1
4
I just want to click a button and get my coordinates for this exact moment/place where i am
我只想点击一个按钮,获取我在这个确切时刻/地点的坐标
That's not possible in general. The device may not know the user's "coordinates for this exact moment/place". You are welcome to call getLastKnownLocation()
on LocationManager
, or perform equivalent sorts of lookups with Play Services' fused location provider, but they may return null
. Usually, to find out where the user is, you request location updates, then react when you get a location fix.
一般来说这是不可能的。设备可能不知道用户的“这个确切时刻/地点的坐标”。您可以在LocationManager上调用getLastKnownLocation(),或者使用Play Services的融合位置提供程序执行等效的查找,但它们可能会返回null。通常,要找出用户所在的位置,请求位置更新,然后在获得位置修复时做出反应。
Every tutorial i've seen its old
每个教程我都看到了它的旧版本
These sample apps (for the fused location provider) and this sample app (for LocationManager
), from my book, should be up to date.
从我的书中,这些示例应用程序(用于融合位置提供程序)和此示例应用程序(用于LocationManager)应该是最新的。
New android versions require permissions to use GPS or Network
新的Android版本需要使用GPS或网络的权限
All Android versions require permissions to determine the user's location, for blindingly obvious privacy reasons. This has been the case since before Android 1.0, and it should remain the case for the foreseeable future.
由于非常明显的隐私原因,所有Android版本都需要权限来确定用户的位置。从Android 1.0开始就是这种情况,在可预见的未来它应该仍然如此。
I am trying to implement those but nothing seems to work
我试图实现这些,但似乎没有任何工作
Then ask a fresh Stack Overflow question, where you provide a minimal, complete, and verifiable example demonstrating your problems.
然后询问一个新的Stack Overflow问题,在那里您提供一个最小,完整且可验证的示例来演示您的问题。
#1
4
I just want to click a button and get my coordinates for this exact moment/place where i am
我只想点击一个按钮,获取我在这个确切时刻/地点的坐标
That's not possible in general. The device may not know the user's "coordinates for this exact moment/place". You are welcome to call getLastKnownLocation()
on LocationManager
, or perform equivalent sorts of lookups with Play Services' fused location provider, but they may return null
. Usually, to find out where the user is, you request location updates, then react when you get a location fix.
一般来说这是不可能的。设备可能不知道用户的“这个确切时刻/地点的坐标”。您可以在LocationManager上调用getLastKnownLocation(),或者使用Play Services的融合位置提供程序执行等效的查找,但它们可能会返回null。通常,要找出用户所在的位置,请求位置更新,然后在获得位置修复时做出反应。
Every tutorial i've seen its old
每个教程我都看到了它的旧版本
These sample apps (for the fused location provider) and this sample app (for LocationManager
), from my book, should be up to date.
从我的书中,这些示例应用程序(用于融合位置提供程序)和此示例应用程序(用于LocationManager)应该是最新的。
New android versions require permissions to use GPS or Network
新的Android版本需要使用GPS或网络的权限
All Android versions require permissions to determine the user's location, for blindingly obvious privacy reasons. This has been the case since before Android 1.0, and it should remain the case for the foreseeable future.
由于非常明显的隐私原因,所有Android版本都需要权限来确定用户的位置。从Android 1.0开始就是这种情况,在可预见的未来它应该仍然如此。
I am trying to implement those but nothing seems to work
我试图实现这些,但似乎没有任何工作
Then ask a fresh Stack Overflow question, where you provide a minimal, complete, and verifiable example demonstrating your problems.
然后询问一个新的Stack Overflow问题,在那里您提供一个最小,完整且可验证的示例来演示您的问题。