Quantcast
Channel: CSDN博客移动开发推荐文章
Viewing all articles
Browse latest Browse all 5930

高德地图-根据经纬度获取地址(逆地理编码)

$
0
0

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);
    }
作者:u010378579 发表于2016/12/28 11:35:07 原文链接
阅读:52 评论:0 查看评论

Viewing all articles
Browse latest Browse all 5930

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>