[英]Java Geocoding - convert latitude and longitude into an address
I need for my Android App the name of the city where my car is located in the moment. 对于我的Android应用程序,我需要当前汽车所在城市的名称。
I have the latitude and longitude and want to convert this with the geocoder in the address and want to get the city. 我具有经度和纬度,并希望将其与地址解析器一起转换,并希望获得城市。
I read some blocks but because I'm new to this I dont get the clue. 我阅读了一些文章,但是由于我是新来的,所以我不知道任何线索。
Please can anyone help me how to do this? 请谁能帮我怎么做?
EDIT: 编辑:
I dont use this geocoding in my app. 我不在我的应用程序中使用此地理编码。 I want to use it in my Java web service and I think I have to this with HTTPRequest, is it?
我想在Java Web服务中使用它,我想必须通过HTTPRequest使用它,对吗? and with the google api url.
以及google api url。
What you are looking for is Reverse Geocoding
. 您正在寻找的是
Reverse Geocoding
。
The Geocoder
class should help you do what you need (taken from here ): Geocoder
类应该可以帮助您完成所需的工作(从此处获取 ):
public static void getAddressFromLocation(
final Location location, final Context context, final Handler handler) {
Thread thread = new Thread() {
@Override public void run() {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
String result = null;
try {
List<Address> list = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 1);
if (list != null && list.size() > 0) {
Address address = list.get(0);
// sending back first address line and locality
result = address.getAddressLine(0) + ", " + address.getLocality();
}
} catch (IOException e) {
Log.e(TAG, "Impossible to connect to Geocoder", e);
} finally {
Message msg = Message.obtain();
msg.setTarget(handler);
if (result != null) {
msg.what = 1;
Bundle bundle = new Bundle();
bundle.putString("address", result);
msg.setData(bundle);
} else
msg.what = 0;
msg.sendToTarget();
}
}
};
thread.start();
}
EDIT: As per your comment, then no, you can't use the Geocoder
class on a normal Java web service. 编辑:根据您的评论,然后,不,您不能在常规Java Web服务上使用
Geocoder
类。 That being said, there are alternatives. 话虽这么说,但还有其他选择。 The Google Geocoding API is usually a good place to start, that being said, they do seem to have limits .
谷歌地理编码API通常是一个不错的起点,也就是说,它们似乎有局限性 。
Alternatively, you could take a look at Nominatim which is an open source Reverse Geocoding service albeit it seems to be slightly limited when compared to Google's services. 另外,您可以看一下Nominatim ,它是一种开源的反向地理编码服务,尽管与Google的服务相比似乎有所限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.