Google map经纬度解析

http://stackoverflow.com/questions/9409195/how-to-get-complete-address-from-latitude-and-longitude

Google map 根据指定经纬度解析出可读的地址信息,也就是地址解码了,主要使用 Geocoder
需要借助两个类GeocoderAddress,可点击查看官方文档。

  • 代码示例:
    List<Address> addresses;
    Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
    String addStr = null;
    try {
        addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
        String address = addresses.get(0).getAddressLine(0);
        String city = addresses.get(0).getLocality();
        String state = addresses.get(0).getAdminArea();
        String zipCode = addresses.get(0).getPostalCode();
        String country = addresses.get(0).getCountryCode();

        addStr = address + "," + city + "," + state + "," + zipCode + "," + country;
        L.e("选择地址", addStr);
    } catch (IOException e) {
        e.printStackTrace();
    }
  • 获取到的信息:
700 Clabber Hill Road,Church Hill,Maryland,21623,US

还可以获取一些其他信息 国家名称 国家代码。。。之类的

注意:
如果返回的 state (州)和 city(市) 为中文,应该是手机默认语言是中文,而Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());Locale.getDefault() 传递的是默认值,所以返回数据是中文。
此时如果服务器统一要求英文,需要手动把手机语言改成英文(很楼),或者代码改成 new Geocoder(mContext, Locale.US)(推荐)。

Logo

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐