1.需要资源:
2.根据经纬度得到具体地址:
1.这里需要用到地图搜索SDK;
2.通过逆地理编码来实现。
3.示例代码:
首先要实现GeocodeSearch.OnGeocodeSearchListener接口
/** * * @author 程龙 */ public class AddEnterprisesActivity extends Activity implements LocationSource, AMapLocationListener, AMap.OnMapClickListener, GeocodeSearch.OnGeocodeSearchListener { @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); //大家可根据自己的需要初始化map和对map进行一些设置,在这里我就不写了。 } /** * map点击事件 * @param latLng 经纬度 */ @Override public void onMapClick(LatLng latLng) { aMap.clear(); latitude = latLng.latitude; longitude = latLng.longitude; MarkerOptions otMarkerOptions = new MarkerOptions(); otMarkerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.weizhi)); otMarkerOptions.position(latLng); getAddressByLatlng(latLng); aMap.addMarker(otMarkerOptions); aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng)); } 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); } //这里再提供另外一种方法 private void getLatlon(String cityName){ GeocodeSearch geocodeSearch=new GeocodeSearch(context); geocodeSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() { @Override public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) { } @Override public void onGeocodeSearched(GeocodeResult geocodeResult, int i) { if (i==1000){ if (geocodeResult!=null && geocodeResult.getGeocodeAddressList()!=null && geocodeResult.getGeocodeAddressList().size()>0){ GeocodeAddress geocodeAddress = geocodeResult.getGeocodeAddressList().get(0); double latitude = geocodeAddress.getLatLonPoint().getLatitude();//纬度 double longititude = geocodeAddress.getLatLonPoint().getLongitude();//经度 String adcode= geocodeAddress.getAdcode();//区域编码 Log.e("地理编码", geocodeAddress.getAdcode()+""); Log.e("纬度latitude",latitude+""); Log.e("经度longititude",longititude+""); }else { ToastUtils.show(context,"地址名出错"); } } } }); GeocodeQuery geocodeQuery=new GeocodeQuery(cityName.trim(),"29"); geocodeSearch.getFromLocationNameAsyn(geocodeQuery); } }
最后大家可根据自己的需要进行修改