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

1.需要資源:
高德地圖搜索SDK以及相關SDk下載地址

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);
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章