高德地圖定位 地圖比例縮放
阿新 • • 發佈:2019-01-24
高德地圖通過Demo中的小籃點定位後地圖比例都很小,想看多一些的地方只能通過手動點選進行選擇,但在選擇的時候可以通過定位+marker的模式定位 並設定比例大小
設定地圖比例 新增中心點
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 13));// 通過定位後獲得的經緯度 為地圖新增中心點 和地圖比例 數字越小地圖顯示越多
public AMapLocationListener mLocationListener = new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation amapLocation) {
// TODO Auto-generated method stub
if (amapLocation != null) {
if (amapLocation.getErrorCode() == 0) {
//定位成功回撥資訊,設定相關訊息
amapLocation.getLocationType();//獲取當前定位結果來源,如網路定位結果,詳見定位型別表
amapLocation.getLatitude();//獲取緯度
amapLocation.getLongitude();//獲取經度
amapLocation.getAccuracy();//獲取精度資訊
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(amapLocation. getTime());
df.format(date);//定位時間
amapLocation.getAddress();//地址,如果option中設定isNeedAddress為false,則沒有此結果,網路定位結果中會有地址資訊,GPS定位不返回地址資訊。
amapLocation.getCountry();//國家資訊
amapLocation.getProvince();//省資訊
amapLocation.getCity();//城市資訊
amapLocation.getDistrict();//城區資訊
amapLocation.getStreet();//街道資訊
amapLocation.getStreetNum();//街道門牌號資訊
amapLocation.getCityCode();//城市編碼
amapLocation.getAdCode();//地區編碼
lat = amapLocation.getLatitude();//獲取緯度
lng =amapLocation.getLongitude();//獲取經度
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 13));// 通過定位後獲得的經緯度 為地圖新增中心點 和地圖比例 數字越小地圖顯示越多
Marker marker;
markerOption = new MarkerOptions().icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.position(new LatLng(lat,lng))
.draggable(true)
.title("當前位置")
.snippet("太原市萬立科技大廈")
.draggable(true);
marker = aMap.addMarker(markerOption);
marker.showInfoWindow();
mLocationClient.stopLocation();//停止定位
} else {
//顯示錯誤資訊ErrCode是錯誤碼,errInfo是錯誤資訊,詳見錯誤碼錶。
Log.e("info","location Error, ErrCode:"
+ amapLocation.getErrorCode() + ", errInfo:"
+ amapLocation.getErrorInfo());
}
}
}
};