如何把API添加到我的Andoid工程中?
<supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:resizeable="true" android:anyDensity="true" />
<!-- 添加百度地图开发的授权 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<!-- 添加显示百度地图的控件 -->
<com.baidu.mapapi.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
在mainActivity中,mainActivity需要继承MapActivity,实现MapActivity中得protected boolean isRouteDisplayed()。下面贴出源码:
public class MainActivity extends MapActivity { private MapView mapview; private BMapManager bMapManager; private String key = "544FAA71566C13CF5A3535787F12CE73970F85EA"; private MapController mapController; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mapview = (MapView)this.findViewById(R.id.mapview); bMapManager = new BMapManager(this); bMapManager.init(key, new MKGeneralListener() { @Override public void onGetPermissionState(int arg0) { if(arg0 == 300){ Toast.makeText(MainActivity.this, "您输入的key有错误!", 1); } } @Override public void onGetNetworkState(int arg0) { // TODO Auto-generated method stub } }); initMapActivity(bMapManager); //设置缩放功能 mapview.setBuiltInZoomControls(true); mapController = mapview.getController(); //设置经纬度:成都 GeoPoint geoPoint = new GeoPoint((int)(30.659*1E6), (int)(104.065*1E6)); mapController.setCenter(geoPoint);//设置一个中心点 mapController.setZoom(12); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); if(bMapManager!=null){ bMapManager.destroy(); bMapManager=null; } } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); if(bMapManager!=null){ bMapManager.start(); } } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); if(bMapManager!=null){ bMapManager.stop(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } }