android 百度地图覆盖物在Activity和Fragment中的实现Word文档下载推荐.docx
《android 百度地图覆盖物在Activity和Fragment中的实现Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《android 百度地图覆盖物在Activity和Fragment中的实现Word文档下载推荐.docx(25页珍藏版)》请在冰豆网上搜索。
-->
android.permission.ACCESS_FINE_LOCATION"
com.android.launcher.permission.READ_SETTINGS"
/>
android.permission.WAKE_LOCK"
android.permission.CHANGE_WIFI_STATE"
android.permission.ACCESS_WIFI_STATE"
android.permission.ACCESS_GPS"
android.permission.READ_PHONE_STATE"
android.permission.READ_CONTACTS"
android.permission.CALL_PHONE"
android.permission.READ_SMS"
android.permission.SEND_SMS"
--SDK1.5需要android.permission.GET_TASKS权限判断本程序是否为当前运行的应用?
android.permission.GET_TASKS"
android.permission.CAMERA"
android.permission.RECORD_AUDIO"
android.permission.WRITE_EXTERNAL_STORAGE"
android.permission.RECEIVE_BOOT_COMPLETED"
android.permission.BROADCAST_STICKY"
android.permission.WRITE_SETTINGS"
--来电消音-->
android.permission.PROCESS_OUTGOING_CALLS"
android.permission.MODIFY_AUDIO_SETTINGS"
supports-screens
android:
anyDensity="
true"
largeScreens="
normalScreens="
false"
resizeable="
smallScreens="
这就是具体的权限设置。
接下来,我们进去真正的功能实现。
首先我们来看在Activity里面的实现。
1.首先编写一个自己的Application类。
2.BaiMapActivity
importandroid.app.Activity;
importandroid.app.AlertDialog;
importandroid.content.BroadcastReceiver;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.content.IntentFilter;
importandroid.os.Bundle;
importandroid.util.Log;
importandroid.widget.Button;
importandroid.widget.LinearLayout;
importandroid.widget.TextView;
importandroid.widget.Toast;
importcom.baidu.mapapi.SDKInitializer;
importcom.baidu.mapapi.map.BaiduMap;
importcom.baidu.mapapi.map.BaiduMap.OnMarkerClickListener;
importcom.baidu.mapapi.map.BaiduMap.OnMarkerDragListener;
importcom.baidu.mapapi.map.BitmapDescriptor;
importcom.baidu.mapapi.map.BitmapDescriptorFactory;
importcom.baidu.mapapi.map.GroundOverlayOptions;
importcom.baidu.mapapi.map.InfoWindow;
importcom.baidu.mapapi.map.InfoWindow.OnInfoWindowClickListener;
importcom.baidu.mapapi.map.MapStatus;
importcom.baidu.mapapi.map.MapStatusUpdate;
importcom.baidu.mapapi.map.MapStatusUpdateFactory;
importcom.baidu.mapapi.map.MapView;
importcom.baidu.mapapi.map.Marker;
importcom.baidu.mapapi.map.MarkerOptions;
importcom.baidu.mapapi.map.OverlayOptions;
importcom.baidu.mapapi.model.LatLng;
importcom.baidu.mapapi.model.LatLngBounds;
publicclassBaiMapActivityextendsActivity{
privatestaticfinalStringLTAG=MainActivity.class.getSimpleName();
/**
*构造广播监听类,监听SDKkey验证以及网络异常广播
*/
publicclassSDKReceiverextendsBroadcastReceiver{
publicvoidonReceive(Contextcontext,Intentintent){
Strings=intent.getAction();
Log.d(LTAG,"
action:
"
+s);
if(s.equals(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR)){
Toast.makeText(BaiMapActivity.this,
"
key验证出错!
请在AndroidManifest.xml文件中检查key设置"
Toast.LENGTH_LONG).show();
}elseif(s
.equals(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR)){
Toast.makeText(BaiMapActivity.this,"
网络出错"
Toast.LENGTH_LONG)
.show();
}
}
}
//
privateSDKReceivermReceiver;
*MapView是地图主控件
privateMapViewmMapView;
privateBaiduMapmBaiduMap;
privateMarkermMarkerA;
privateMarkermMarkerB;
privateMarkermMarkerC;
//privateMarkermMarkerD;
privateInfoWindowmInfoWindow;
//初始化全局bitmap信息,不用时及时recycle
BitmapDescriptorbdA=null;
BitmapDescriptorbdB=null;
BitmapDescriptorbdC=null;
//BitmapDescriptorbdD=BitmapDescriptorFactory
//.fromResource(R.drawable.icon_markd);
BitmapDescriptorbd=null;
BitmapDescriptorbdGround=null;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity);
//注册SDK广播监听者
IntentFilteriFilter=newIntentFilter();
iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
mReceiver=newSDKReceiver();
registerReceiver(mReceiver,iFilter);
//初始化全局bitmap信息,不用时及时recycle
bdA=BitmapDescriptorFactory.fromResource(R.drawable.bmt);
bdB=BitmapDescriptorFactory.fromResource(R.drawable.bmt);
bdC=BitmapDescriptorFactory.fromResource(R.drawable.bmt);
//BitmapDescriptorbdD=BitmapDescriptorFactory
//.fromResource(R.drawable.icon_markd);
bd=BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
bdGround=BitmapDescriptorFactory
.fromResource(R.drawable.ground_overlay);
mMapView=(MapView)findViewById(R.id.bmapView);
mBaiduMap=mMapView.getMap();
//设定中心点坐标
LatLngcenpt=newLatLng(36.05,103.83);
//定义地图状态
MapStatusmMapStatus=newMapStatus.Builder().target(cenpt).zoom(18)
.build();
//定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
MapStatusUpdatemMapStatusUpdate=MapStatusUpdateFactory
.newMapStatus(mMapStatus);
//改变地图状态
mBaiduMap.setMapStatus(mMapStatusUpdate);
MapStatusUpdatemsu=MapStatusUpdateFactory.zoomTo(14.0f);
mBaiduMap.setMapStatus(msu);
initOverlay();
mBaiduMap.setOnMarkerClickListener(newOnMarkerClickListener(){
publicbooleanonMarkerClick(finalMarkermarker){
Log.e("
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
"
mjhvvj"
+marker);
Buttonbutton=newButton(getApplicationContext());
button.setBackgroundResource(R.drawable.popup);
OnInfoWindowClickListenerlistener=null;
if(marker==mMarkerA){
window();
//button.setText("
更改位置"
);
//listener=newOnInfoWindowClickListener(){
//publicvoidonInfoWindowClick(){
//
//window();
//LatLngll=marker.getPosition();
//LatLngllNew=newLatLng(ll.latitude+0.005,
//ll.longitude+0.005);
//marker.setPosition(llNew);
//mBaiduMap.hideInfoWindow();
//}
//};
//mInfoWindow=newInfoWindow(BitmapDescriptorFactory
//.fromView(button),ll,-47,listener);
//mBaiduMap.showInfoWindow(mInfoWindow);
}elseif(marker==mMarkerB){
更改图标"
//button.setOnClickListener(newOnClickListener(){
//publicvoidonClick(Viewv){
////marker.setIcon(bd);
//});
//mInfoWindow=newInfoWindow(button,ll,-47);
}elseif(marker==mMarkerC){
删除"
////marker.remove();
}
returntrue;
});
publicvoidinitOverlay(){
//添加覆盖物的坐标
LatLngllA=newLatLng(36.05,103.83);
LatLngllB=newLatLng(36.15,103.78);
LatLngllC=newLatLng(36.20,103.65);
LatLngllD=newLatLng(36.25,103.32);
OverlayOptionsooA=newMarkerOptions().position(llA).icon(bdA)
.zIndex(9).draggable(true);
mMarkerA=(Marker)(mBaiduMap.addOverlay(ooA));
OverlayOptionsooB=newMarkerOptions().position(llB).icon(bdB)
.zIndex(5);
mMarkerB=(Marker)(mBaiduMap.addOverlay(ooB));
OverlayOptionsooC=newMarkerOptions().position(llC).icon(bdC)
.perspective(false).anchor(0.5f,0.5f).rotate(30).zIndex(7);
mMarkerC=(Marker)(mBaiduMap.addOverlay(ooC));
//ArrayList<
BitmapDescriptor>
giflist=new
();
//giflist.add(bdA);
//giflist.add(bdB);
//giflist.add(bdC);
//OverlayOptionsooD=newMarkerOptions().position(llD).icons(giflist)
//.zIndex(0).period(10);
//mMarkerD=(Marker)(mBaiduMap.addOverlay(ooD));
//添加弹出窗覆盖物的区域
LatLng