高德相关

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);
}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值