我怎样才能获得该设备的当前地理位置编程 [英] How I can get current geographical location of the device programatically
问题描述
我需要得到设备的当前地理位置。
I need to get the device's current geographical location.
情景:如果我在美
..
Scenario : if I am in US
..:
my device location should be US
相同的情况下,当我在英国
:
my device location should be UK
我需要样品$ C $下找到这个地理位置。(位置由网络位置提供程序确定
)
推荐答案
如果你想获得当前国家code,你想看看<一href="http://developer.android.com/reference/android/location/Geo$c$cr.html"><$c$c>Geo$c$cr$c$c>你可以用它来获得一个 地址
它提供了一个<一个href="http://developer.android.com/reference/android/location/Address.html#getCountry$c$c%28%29"><$c$c>getCountry$c$c$c$c>方法。事情是这样的。
If you want to get the current country code, you want to look into Geocoder
which you can use to get an Address
which provides a getCountryCode
method. Something like this
Geocoder geocoder = new Geocoder(this);
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(
location.getLatitude(),
location.getLongitude(), 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses != null && addresses.size() > 0) {
Address address = addresses.get(0);
String countryCode = address.getCountryCode();
}
至于获取当前的纬度和经度,有大量的信息在那里就如何做到这一点
As far as getting the current latitude and longitude, there is plenty of information out there on how to do that
- <一个href="http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android">How我是否能够得到当前GPS位置编程方式在Android的?
- <一个href="http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-a">What是获得在Android的用户的当前位置,最简单,最可靠的方法?
- <一个href="http://developer.android.com/guide/topics/location/index.html">http://developer.android.com/guide/topics/location/index.html
- How do I get the current GPS location programmatically in Android?
- What is the simplest and most robust way to get the user's current location in Android?
- http://developer.android.com/guide/topics/location/index.html
这篇关于我怎样才能获得该设备的当前地理位置编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!