通过经纬度获取地名

来源:互联网 发布:java string split n 编辑:程序博客网 时间:2024/05/17 02:03

方法一:Java 根据经纬度获取地址

  1.  //参数解释: 纬度,经度 type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项
  1. String urlString = "http://gc.ditu.aliyun.com/regeocoding?l="+lat+","+log+"&type=010"
将经纬度的值组合到上面链接中,会得到json,然后进行解析获取需要的数据,
例如:http://gc.ditu.aliyun.com/regeocoding?l=36.6424,107.6821&type=010 得到json如下:

{    "queryLocation": [        36.6424,         107.6821    ],     "addrList": [        {            "type": "poi",             "status": 1,             "name": "湾里",             "id": "ANB03A60HZ36",             "admCode": "621023",             "admName": "甘肃省,庆阳市,华池县,",             "addr": "",             "nearestPoint": [                107.68472,                 36.64138            ],             "distance": 281.155        }    ]}

方法二:逆地理转换-根据经纬度获取地址


import android.location.Address;
import android.location.Geocoder;
代码:
String mcityName = null;
Geocoder geocoder = new Geocoder(mContext);
List<Address> addList = geocoder.getFromLocation(latitude, longitude, 1);// 解析经纬度
if (addList != null && addList.size() > 0) {
for (int i = 0; i < addList.size(); i++) {
Address add = addList.get(i);
mcityName = add.getLocality();
}
}
Log.i("---->map中心点地名:", mcityName);


1 0