对于百度jar包调用这块还是容易犯错误
一旦出错,运行调试困难,报的错误仅仅是无法启动activity,这种情况一定要查看jar包是否正确引用
特此将开发步骤与jar的引用说明一下
1步:下载jar包,两个文件一个jar一个so文件
http://developer.baidu.com/map/sdkandev-download.htm
//右下角有个"lib库"
2步:工程内引入库,将so文件放在工程的libs/armeabi 下面 //没有请新建文件夹
将jar文件放入libs下面
3步:选择工程右键属性->java bulid path->libraries->add jars选择你的工程内libs下的jar(上步放入的) OK就完成了包的引用
4步:给manifest添加权限(很重要)
1 |
< uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" /> |
2 |
< uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION" /> |
3 |
< uses-permission android:name = "android.permission.INTERNET" /> |
4 |
< uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" /> |
5 |
< uses-permission android:name = "android.permission.ACCESS_WIFI_STATE" /> |
6 |
< uses-permission android:name = "android.permission.CHANGE_WIFI_STATE" /> |
7 |
< uses-permission android:name = "android.permission.READ_PHONE_STATE" /> |
5步:布局layout 之 main.xml
01 |
<? xml version = "1.0" encoding = "utf-8" ?> |
02 |
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
03 |
android:orientation = "vertical" |
04 |
android:layout_width = "fill_parent" |
05 |
android:layout_height = "fill_parent" |
07 |
< com.baidu.mapapi.MapView android:id = "@+id/map_View" |
08 |
android:layout_width = "fill_parent" |
09 |
android:layout_height = "fill_parent" |
10 |
android:clickable = "true" |
6步:开发百度地图,需要申请个Key,很简单,只需几秒钟时间即可完成。 http://developer.baidu.com/map/android-mobile-apply-key.htm
7步:示例mainActivity
01 |
public class MainActivity extends MapActivity
{ |
02 |
private BMapManager
mapManager; |
03 |
private MapView
mapView; |
04 |
private MapController
mapController; |
07 |
public void onCreate(Bundle
savedInstanceState) { |
08 |
super .onCreate(savedInstanceState); |
09 |
setContentView(R.layout.main); |
12 |
mapManager
= new BMapManager(getApplication()); |
14 |
mapManager.init( "285B415EBAB2A92293E85502150ADA7F03C777C4" , null ); |
15 |
super .initMapActivity(mapManager); |
17 |
mapView
= (MapView) findViewById(R.id.map_View); |
19 |
mapView.setTraffic( true ); |
21 |
mapView.setBuiltInZoomControls( true ); |
24 |
GeoPoint
point = new GeoPoint(( int )
( 47.118440 *
1E6), ( int )
( 87.493147 *
1E6)); |
27 |
Drawable
marker = this .getResources().getDrawable(R.drawable.iconmarka); |
29 |
marker.setBounds( 0 , 0 ,
marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); |
32 |
mapController
= mapView.getController(); |
34 |
mapController.setCenter(point); |
36 |
mapController.setZoom( 12 ); |
40 |
protected boolean isRouteDisplayed()
{ |
45 |
protected void onDestroy()
{ |
46 |
if (mapManager
!= null )
{ |
54 |
protected void onPause()
{ |
55 |
if (mapManager
!= null )
{ |
62 |
protected void onResume()
{ |
63 |
if (mapManager
!= null )
{ |