一:使用百度地圖的Key
二:mapView
//找到mapView控件
MapView mapview = findViewById(R.id.mapview);
//是否顯示縮放按鈕
mapview.showZoomControls(false);
//是否顯示地圖縮放標(biāo)尺
mapview.showScalseControl(false);
//獲取地圖管理器,管理MapView :縮放 旋轉(zhuǎn)移動(dòng)
BaiduMap baiduMap = mapview.getMap();
//設(shè)置縮放級(jí)別
baiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(15));//默認(rèn)級(jí)別為12
//設(shè)置默認(rèn)中心點(diǎn)
baiduMap.setMapStatus(MapStatusUpdateFactory.newLatlng(new latLng(維度,經(jīng)度)))
public boolean onKeyDown(int keyCode,keyEvent event){
//在當(dāng)前級(jí)別上放大一個(gè)級(jí)別
baiduMap.setMapStatus(MapStatusUpdateFactory.zoomIn());
//在當(dāng)前級(jí)別上縮小一個(gè)級(jí)別
baiduMap.setMapStatus(MapStatusUpdateFactory.zoomOut());
//旋轉(zhuǎn) 以地圖中線點(diǎn)順時(shí)針逆時(shí)針旋轉(zhuǎn)
float rotate = baiduMap.getMapStatus().rotate;//獲取當(dāng)前地圖的旋轉(zhuǎn)角度
//把角度類加后 重新設(shè)置給地圖
MapStatus rotateStatus = new MapStatus.Builder().rotate(rotate + 30).build();;//范圍是0-360
baiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus( rotateStatus));
//俯角旋轉(zhuǎn)
float overlook = baiduMap.getMapStatus().overlook;//獲取當(dāng)前地圖的角度
MapStatus overlookStatus = new MapStatus.Builder().overlook(overlook - 15).build();;//范圍是0- (-45)
baiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus( overlookStatus));
//移動(dòng)到一個(gè)點(diǎn)
baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng( new LatLng(維度,經(jīng)度)));
}
圖層
//顯示底圖
baiduMap.setMaptype(BaiduMap.MAP_TYPE_NORMAL)
//顯示交通圖
baiduMap.setTrafficEnabled(true);
//顯示衛(wèi)星圖
baiduMap.setMapType(BaiduMap.MAP_TYPE_SATETTITE)
//繪制圓形覆蓋物
//創(chuàng)建覆蓋物對(duì)象
CircleOptions circleOptions = new CircleOptions();
LatLng latlng = new LatLng(維度,經(jīng)度);
//設(shè)置數(shù)據(jù)
circleOptions.center(latlng);//設(shè)置中心點(diǎn)
circleOptions.fillColor(顏色值)//設(shè)置填充顏色
circleOptions.radius(1000)//設(shè)置半徑 單位是米
circleOptions.stroke(new Stroke (5,顏色值));//邊框 寬度和顏色
//把覆蓋物添加到底圖上
baiduMap.addOverlay(circleOptions)
//添加文字
TextOptions textOptions = new TextOptions();
textOptions.postion(latlng)//設(shè)置位置
textOptions.bgColor()//設(shè)置背景顏色
textOptions.fontColor()//設(shè)置文字顏色
textOptions.fonSize()//設(shè)置字體大小
textOptions.typeface(Typeface.SERIF)//設(shè)置字體
textOptions.text(" ")//設(shè)置文字內(nèi)容
baiduMap.addOverlay(textOptions);//添加到底圖上
//MArKeR覆蓋物 可設(shè)置圖片.點(diǎn)擊事件
BitmapDescriptor icon = BitmapDescriptorFactory.
MarkerOptions options = new MarkerOoptions();
markerOptions.postion(latlng)
.icon(icon)//設(shè)置圖片 可添加集合 集合添加多張圖片
.title("文字");
.draggable(true)//可拖動(dòng)
baiduMap.addOverlay(option)
//把事件傳遞該Marker覆蓋物
baiduMap.setOnMarkerClickListener(this);
//添加點(diǎn)擊彈出控件
VIew pop = View.inflate(this,布局文件,null);
pop.setCisiblity(View.INVISIBLE);
MapViewLayoutParams param = new MapViewLayoutParams.Builder()
.layoutMode(ELayoutMdoe.mapMode)//使用經(jīng)緯度模式
.postion(latlng)
.width(MapViewLayoutParams.WRAP_CONTNENT)
.height(MapViewLayoutParams.WRAP_CONTNENT)
.yOffset(-10)//向上移動(dòng)
.build();
mapView.addView(pop,param);
調(diào)用相對(duì)應(yīng)的生命周期
PRotected void onResume(){
mapview.onResume();
super.onResume();
}
protected void onPause(){
mapview.onPause();
super.onPause();
}
protected void onDestory(){
mapview.onDestory();
super.onDestory();
}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注