小编今天介绍两种方案:
一、高德地图
1、在build.gradle添加依赖:compile 'com.amap.api:search:latest.integration'
2、编写java代码
private fun setAddress(lat: Double?, lon: Double?) { if (lat == null || lon == null) { tv_adress.text = "暂无" } else { val latLng = LatLng(lat, lon) val gs = GeocodeSearch(this) //逆地理编码查询条件:逆地理编码查询的地理坐标点、查询范围、坐标类型。 val latLonPoint = LatLonPoint(latLng.latitude, latLng.longitude) val query = RegeocodeQuery(latLonPoint, 500f, GeocodeSearch.AMAP) //异步查询 gs.getFromLocationAsyn(query) gs.setOnGeocodeSearchListener(object : GeocodeSearch.OnGeocodeSearchListener { override fun onGeocodeSearched(p0: GeocodeResult?, p1: Int) { } override fun onRegeocodeSearched(regeocodeResult: RegeocodeResult?, p1: Int) { if (p1 == 1000) { val regeocodeAddress = regeocodeResult!!.regeocodeAddress val formatAddress = regeocodeAddress.formatAddress if (formatAddress != null) { tv_adress.text = formatAddress } } } }) } }
二、百度地图api
1、api的官方文档:http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding
2、例如:http://api.map.baidu.com/geocoder/v2/?location=30.572998,104.067046&output=json&pois=0&ak=YBqIaSUHGsebc76AiGPGWkE0YGbELfAG
ggband