我想要实际的地点或建筑物名称,而不是使用 GPS 的 andoird 应用程序中的地址。
例如:如果我在购物中心,我的应用程序应该显示我在 XXXX 购物中心。
目前我正在使用纬度和经度获取地址。
如果遵循这个http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/
最佳答案
通过使用 Google Geocoder你将能够实现你所寻求的。它返回 Address
包含有关您传递给它的 latitude
和 longitude
位置的所有信息的对象。下面是如何使用它的示例:
if (Geocoder.isPresent()) {
Geocoder gc = new Geocoder(context);
List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
// do stuff with addresses
}
如果它无法返回一个好的 Address
对象,您仍然可以尝试使用 url 方法:
URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?latlng=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "&sensor=false&language=" + Locale.getDefault().getLanguage());
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
InputStream in = connection.getInputStream();
JSONObject responseData;
try {
Scanner s = new Scanner(in).useDelimiter("\\A");
try {
String text = s.next();
responseData = new JSONObject(text);
} finally {
s.close();
}
} finally {
in.close();
}
// Do stuff with responseData, all the usefull informations are in this payload
关于android - 我如何使用 GPS 在 android 中找到地点或建筑物名称而不是地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35450282/