您的位置:首页 > 移动开发 > Android开发

高德地图android sdk 逆地理编码 基本使用方法

2013-12-17 11:00 375 查看
逆地理编码很简单,直接贴代码,

public void onLocationChanged(AMapLocation aMapLocation)是上一篇中用到的,定位成功后的回调接口

@Override
public void onLocationChanged(AMapLocation aMapLocation) {
// TODO Auto-generated method stub
if (onLocationChangedListener != null && aMapLocation != null) {
onLocationChangedListener.onLocationChanged(aMapLocation);// 显示系统小蓝点
float bearing = aMap.getCameraPosition().bearing;
aMap.setMyLocationRotateAngle(bearing);// 设置小蓝点旋转角度
}

GeocodeSearch geocoderSearch = new GeocodeSearch(this);//传入context
LatLonPoint latLonPoint = new LatLonPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200, GeocodeSearch.AMAP);
geocoderSearch.setOnGeocodeSearchListener(new OnGeocodeSearchListener() {
/**
* 逆地理编码回调
*/
@Override
public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
if (rCode == 0) {
// if (result != null && result.getRegeocodeAddress() !=
// null
// && result.getRegeocodeAddress().getFormatAddress() !=
// null) {
// addressName =
// result.getRegeocodeAddress().getFormatAddress()
// + "附近";
List<PoiItem> poiItems = result.getRegeocodeAddress().getPois();
for (PoiItem poiItem : poiItems) {
Log.v("zhangzida", poiItem.getTitle());//输出周边poi的信息
}
// Log.v("zhangzida",
// result.getRegeocodeAddress().getNeighborhood());
// ToastUtil.show(GeocoderActivity.this, addressName);
} else {
// ToastUtil.show(GeocoderActivity.this,
// R.string.no_result);
}
// else if (rCode == 27) {
// ToastUtil.show(GeocoderActivity.this,
// R.string.error_network);
// } else if (rCode == 32) {
// ToastUtil.show(GeocoderActivity.this, R.string.error_key);
// } else {
// ToastUtil.show(GeocoderActivity.this, R.string.error_other);
// }

}

@Override
public void onGeocodeSearched(GeocodeResult arg0, int arg1) {
// TODO Auto-generated method stub

}

});
geocoderSearch.getFromLocationAsyn(query);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息