1. 程式人生 > >高德地圖-根據經緯度獲取地址(逆地理編碼)

高德地圖-根據經緯度獲取地址(逆地理編碼)

2.根據經緯度得到具體地址:

1.這裡需要用到地圖搜尋SDK;
2.通過逆地理編碼來實現。

3.示例程式碼:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chose_address);

        initUi();
        mapView.onCreate(savedInstanceState);
    }
    @Override
protected void initUi() { mapView = (MapView) findViewById(R.id.mv_map); aMap = mapView.getMap(); aMap.setOnMapLongClickListener(this); //地理搜尋類 geocodeSearch = new GeocodeSearch(this); geocodeSearch.setOnGeocodeSearchListener(this); } private
void getAddressByLatlng(LatLng latLng) { //逆地理編碼查詢條件:逆地理編碼查詢的地理座標點、查詢範圍、座標型別。 LatLonPoint latLonPoint = new LatLonPoint(latLng.latitude, latLng.longitude); RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 500f, GeocodeSearch.AMAP); //非同步查詢 geocodeSearch.getFromLocationAsyn(query); } //得到逆地理編碼非同步查詢結果
@Override public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) { RegeocodeAddress regeocodeAddress = regeocodeResult.getRegeocodeAddress(); String formatAddress = regeocodeAddress.getFormatAddress(); simpleAddress = formatAddress.substring(9); tvChoseAddress.setText("查詢經緯度對應詳細地址:\n" + simpleAddress); }