Android 高德地图根据经纬度定位到指定位置,并使用icon标记
//移动到指定经纬度
private void initAMap() {
AMap mAMap = mMapView.getMap();
CameraPosition cameraPosition = new CameraPosition(new LatLng(latitude, longitude), 15, 0, 30);
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition);
mAMap.moveCamera(cameraUpdate);
drawMarkers();
}
//画定位标记图
public void drawMarkers() {
MarkerOptions markerOptions = new MarkerOptions()
.position(new LatLng(latitude, longitude))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.daohang_location))
.draggable(true);
Marker marker = mAMap.addMarker(markerOptions);
marker.showInfoWindow();
}
已知地址获取经纬度方法:
private void getLatlon(String cityName){
GeocodeSearch geocodeSearch=new GeocodeSearch(this);
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("lgq地理编码", geocodeAddress.getAdcode()+"");
Log.e("lgq纬度latitude",latitude+"");
Log.e("lgq经度longititude",longititude+"");
Log.i("lgq","dddwww===="+longititude);
}else {
Toast.makeText(MainActivity.this,"地名出错",Toast.LENGTH_SHORT).show();
// ToastUtils.show(context,"地址名出错");
}
}
}
});
GeocodeQuery geocodeQuery=new GeocodeQuery(cityName.trim(),"29");
geocodeSearch.getFromLocationNameAsyn(geocodeQuery);
}