高德地圖逆編碼和正編碼

/**

* 通過(guò)經(jīng)緯度獲取當(dāng)前地址詳細(xì)信息,逆地址編碼

* @param latitude

* @param longitude

*/

```

getAddressInfoByLatLong(cameraPosition.target.latitude, cameraPosition.target.longitude); //傳入經(jīng)緯度

private void getAddressInfoByLatLong(double latitude, double longitude) {

? ? GeocodeSearch geocodeSearch = new GeocodeSearch(this);

? ? /*

? ? point - 要進(jìn)行逆地理編碼的地理坐標(biāo)點(diǎn)。

? ? radius - 查找范圍。默認(rèn)值為1000,取值范圍1-3000,單位米。

? ? latLonType - 輸入?yún)?shù)坐標(biāo)類型。包含GPS坐標(biāo)和高德坐標(biāo)。 可以參考RegeocodeQuery.setLatLonType(String)

? ? */

? ? RegeocodeQuery query = new RegeocodeQuery(new LatLonPoint(latitude, longitude), 3000, GeocodeSearch.AMAP);

? ? geocodeSearch.getFromLocationAsyn(query);

? ? geocodeSearch.setOnGeocodeSearchListener(mOnGeocodeSearchListener);

}

/**

* 響應(yīng)地理編碼

*/

getLatlon("河南省鄭州市中原區(qū)");? //傳入詳情地址

public void getLatlon(final String name) {

GeocodeSearch geocoderSearch =new GeocodeSearch(this);

? ? GeocodeQuery query =new GeocodeQuery(name, "");// 第一個(gè)參數(shù)表示地址,第二個(gè)參數(shù)表示查詢城市,中文或者中文全拼,citycode、adcode,

? ? geocoderSearch.getFromLocationNameAsyn(query);// 設(shè)置同步地理編碼請(qǐng)求

? ? geocoderSearch.setOnGeocodeSearchListener(mOnGeocodeSearchListener);

}


private void initListener() {? //初始化

//逆地址搜索監(jiān)聽(tīng)器

? ? ? ? mOnGeocodeSearchListener =new GeocodeSearch.OnGeocodeSearchListener() {

@Override

? ? ? ? ? ? public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {

if (i ==1000) {

if (regeocodeResult !=null) {

Logger.e("ss", "? ____" + regeocodeResult.getRegeocodeAddress().getFormatAddress());

? ? ? ? ? ? ? ? ? ? ? ? Logger.e("ss", regeocodeResult.getRegeocodeAddress().getProvince() +"? " + regeocodeResult.getRegeocodeAddress().getCity() +"" +"? " + regeocodeResult.getRegeocodeAddress().getDistrict());

? ? ? ? ? ? ? ? ? ? ? ? tv_address.setText(regeocodeResult.getRegeocodeAddress().getProvince() + regeocodeResult.getRegeocodeAddress().getCity() + regeocodeResult.getRegeocodeAddress().getDistrict());

? ? ? ? ? ? ? ? ? ? }

}

}

//正地理編碼

? ? ? ? ? ? @Override

? ? ? ? ? ? public void onGeocodeSearched(GeocodeResult result, int rCode) {

if (rCode == AMapException.CODE_AMAP_SUCCESS) {

if (result !=null && result.getGeocodeAddressList() !=null

? ? ? ? ? ? ? ? ? ? ? ? ? ? && result.getGeocodeAddressList().size() >0) {

GeocodeAddress address = result.getGeocodeAddressList().get(0);

? ? ? ? ? ? ? ? ? ? ? ? if (address !=null) {

aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(

convertToLatLng(address.getLatLonPoint()), 15));

? ? ? ? ? ? ? ? ? ? ? ? ? ? geoMarker.setPosition(convertToLatLng(address

.getLatLonPoint()));

? ? ? ? ? ? ? ? ? ? ? ? ? ? addressName ="經(jīng)緯度值:" + address.getLatLonPoint() +"\n位置描述:"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? + address.getFormatAddress();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ToastUtil.show(ShareLocationActivity1.this, addressName);

? ? ? ? ? ? ? ? ? ? ? ? }

}else {

ToastUtil.show(ShareLocationActivity1.this, R.string.no_result);

? ? ? ? ? ? ? ? ? ? }

}else {

//? ? ? ? ? ? ? ? ? ? ToastUtil.showerror(this, rCode);

? ? ? ? ? ? ? ? }

}};

? ? }

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容