1、 -android.permission.ACCESS_FINE_LOCATIONcom.android.launcher.permission.READ_SETTINGS /android.permission.WAKE_LOCKandroid.permission.CHANGE_WIFI_STATEandroid.permission.ACCESS_WIFI_STATEandroid.permission.ACCESS_GPSandroid.permission.READ_PHONE_STATEandroid.permission.READ_CONTACTSandroid.permissi
2、on.CALL_PHONEandroid.permission.READ_SMSandroid.permission.SEND_SMS- SDK1.5需要android.permission.GET_TASKS权限判断本程序是否为当前运行的应用?android.permission.GET_TASKSandroid.permission.CAMERAandroid.permission.RECORD_AUDIOandroid.permission.WRITE_EXTERNAL_STORAGEandroid.permission.RECEIVE_BOOT_COMPLETEDandroid.per
3、mission.BROADCAST_STICKYandroid.permission.WRITE_SETTINGS- 来电消音 -android.permission.PROCESS_OUTGOING_CALLSandroid.permission.MODIFY_AUDIO_SETTINGSsupports-screens android:anyDensity=truelargeScreens=normalScreens=falseresizeable=smallScreens=这就是具体的权限设置。 接下来,我们进去真正的功能实现。 首先我们来看在Activity里面的实现。 1. 首先编写
4、一个自己的Application类。2.BaiMapActivityimport android.app.Activity;import android.app.AlertDialog;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.os.Bundle;import android.util.Log;import android.widge
5、t.Button;import android.widget.LinearLayout;import android.widget.TextView;import android.widget.Toast;import com.baidu.mapapi.SDKInitializer;import com.baidu.mapapi.map.BaiduMap;import com.baidu.mapapi.map.BaiduMap.OnMarkerClickListener;import com.baidu.mapapi.map.BaiduMap.OnMarkerDragListener;impo
6、rt com.baidu.mapapi.map.BitmapDescriptor;import com.baidu.mapapi.map.BitmapDescriptorFactory;import com.baidu.mapapi.map.GroundOverlayOptions;import com.baidu.mapapi.map.InfoWindow;import com.baidu.mapapi.map.InfoWindow.OnInfoWindowClickListener;import com.baidu.mapapi.map.MapStatus;import com.baidu
7、.mapapi.map.MapStatusUpdate;import com.baidu.mapapi.map.MapStatusUpdateFactory;import com.baidu.mapapi.map.MapView;import com.baidu.mapapi.map.Marker;import com.baidu.mapapi.map.MarkerOptions;import com.baidu.mapapi.map.OverlayOptions;import com.baidu.mapapi.model.LatLng;import com.baidu.mapapi.mode
8、l.LatLngBounds;public class BaiMapActivity extends Activity private static final String LTAG = MainActivity.class.getSimpleName(); /* * 构造广播监听类,监听 SDK key 验证以及网络异常广播 */ public class SDKReceiver extends BroadcastReceiver public void onReceive(Context context, Intent intent) String s = intent.getActio
9、n(); 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(); else if (s .equals(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR) T
10、oast.makeText(BaiMapActivity.this, 网络出错, Toast.LENGTH_LONG) .show(); / private SDKReceiver mReceiver; * MapView 是地图主控件 private MapView mMapView; private BaiduMap mBaiduMap; private Marker mMarkerA; private Marker mMarkerB; private Marker mMarkerC; / private Marker mMarkerD; private InfoWindow mInfoW
11、indow; / 初始化全局 bitmap 信息,不用时及时 recycle BitmapDescriptor bdA = null; BitmapDescriptor bdB = null; BitmapDescriptor bdC = null; / BitmapDescriptor bdD = BitmapDescriptorFactory / .fromResource(R.drawable.icon_markd); BitmapDescriptor bd = null; BitmapDescriptor bdGround = null; Override public void on
12、Create(Bundle savedInstanceState) super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext(); setContentView(R.layout.activity); / 注册 SDK 广播监听者 IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
13、 iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR); mReceiver = new SDKReceiver(); registerReceiver(mReceiver, iFilter); / 初始化全局 bitmap 信息,不用时及时 recycle bdA = BitmapDescriptorFactory.fromResource(R.drawable.bmt); bdB = BitmapDescriptorFactory.fromResource(R.drawable.bmt); b
14、dC = BitmapDescriptorFactory.fromResource(R.drawable.bmt); / BitmapDescriptor bdD = BitmapDescriptorFactory / .fromResource(R.drawable.icon_markd); bd = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding); bdGround = BitmapDescriptorFactory .fromResource(R.drawable.ground_overlay); mMapVie
15、w = (MapView) findViewById(R.id.bmapView); mBaiduMap = mMapView.getMap(); / 设定中心点坐标 LatLng cenpt = new LatLng(36.05, 103.83); / 定义地图状态 MapStatus mMapStatus = new MapStatus.Builder().target(cenpt).zoom(18) .build(); / 定义MapStatusUpdate对象,以便描述地图状态将要发生的变化 MapStatusUpdate mMapStatusUpdate = MapStatusUpd
16、ateFactory .newMapStatus(mMapStatus); / 改变地图状态 mBaiduMap.setMapStatus(mMapStatusUpdate); MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(14.0f); mBaiduMap.setMapStatus(msu); initOverlay(); mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() public boolean onMarkerClick(final Marker ma
17、rker) Log.e(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, mjhvvj + marker); Button button = new Button(getApplicationContext(); button.setBackgroundResource(R.drawable.popup); OnInfoWindowClickListener listener = null; if (marker = mMarkerA) window(); / button.setText(更改位置); / listener = new OnInfoWindowClickL
18、istener() / public void onInfoWindowClick() / / window(); / LatLng ll = marker.getPosition(); / LatLng llNew = new LatLng(ll.latitude + 0.005, / ll.longitude + 0.005); / marker.setPosition(llNew); / mBaiduMap.hideInfoWindow(); / / ; / mInfoWindow = new InfoWindow(BitmapDescriptorFactory / .fromView(
19、button), ll, -47, listener); / mBaiduMap.showInfoWindow(mInfoWindow); else if (marker = mMarkerB) 更改图标 / button.setOnClickListener(new OnClickListener() / public void onClick(View v) / / marker.setIcon(bd); / ); / mInfoWindow = new InfoWindow(button, ll, -47); else if (marker = mMarkerC) 删除 / / mark
20、er.remove(); return true; ); public void initOverlay() / 添加覆盖物的坐标 LatLng llA = new LatLng(36.05, 103.83); LatLng llB = new LatLng(36.15, 103.78); LatLng llC = new LatLng(36.20, 103.65); LatLng llD = new LatLng(36.25, 103.32); OverlayOptions ooA = new MarkerOptions().position(llA).icon(bdA) .zIndex(9
21、).draggable(true); mMarkerA = (Marker) (mBaiduMap.addOverlay(ooA); OverlayOptions ooB = new MarkerOptions().position(llB).icon(bdB) .zIndex(5); mMarkerB = (Marker) (mBaiduMap.addOverlay(ooB); OverlayOptions ooC = new MarkerOptions().position(llC).icon(bdC) .perspective(false).anchor(0.5f, 0.5f).rota
22、te(30).zIndex(7); mMarkerC = (Marker) (mBaiduMap.addOverlay(ooC); / ArrayList giflist = new(); / giflist.add(bdA); / giflist.add(bdB); / giflist.add(bdC); / OverlayOptions ooD = new MarkerOptions().position(llD).icons(giflist) / .zIndex(0).period(10); / mMarkerD = (Marker) (mBaiduMap.addOverlay(ooD); / 添加弹出窗覆盖物的区域 LatLng
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1