/**
通過經(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)聽器
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);
}
}};
}