简体   繁体   English

Java Geocoding-将经纬度转换为地址

[英]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.

相关问题 在Java中将地址转换为纬度和经度,以获得基于距离的建议 - Convert address to latitude and longitude in java for distance based suggestion 地理编码,获取角落纬度经度 - geocoding, get corner latitude longitude 如何将HEXEWKB转换为Latitude,Longitude(在java中)? - How to convert HEXEWKB to Latitude, Longitude (in java)? 将纬度和经度值(度)转换为Double。 爪哇 - Convert Latitude and Longitude Values (Degrees) to Double . Java 在java中将纬度和经度转换为北向和东向? - convert latitude and longitude to northing and easting in java? 如何获取给定城市或地址名称的纬度和经度(java代码)? - how to get Latitude and Longitude of the given Name of the City or Address (java code)? 接受地址并返回经度和纬度坐标的Java函数 - Java function that accepts address and returns longitude and latitude coordinates 在java中通过Google获取地址的经度和纬度的最佳方法是什么? - What is the best way to get longitude and latitude for an address via Google in java 使用Java从Android Studio中的Google Geocoding API获取经度和纬度值 - Get Longitude and Latitude values from Google Geocoding API in Android Studio with Java 如何在Java中将经度和纬度从十进制dms转换为度 - How to convert latitude and longitude from decimal dms to degree in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM