ä¸ãç³è¯·å¯é¥
1ãå
ç¨eclipseå建ä¸ä¸ªAndroidå·¥ç¨
2ãå¨ç¾åº¦apiå®ç½ä¸ç³è¯·ä¸ä¸ªå¯é¥ï¼é¾æ¥ï¼
http://lbsyun.baidu.com/apiconsole/keybubuko.com,å¸å¸æ£
äºãå·¥ç¨é
ç½®
1ãå°baidumapapi_vX_X_X.jaræ·è´å°å·¥ç¨libsç®å½ä¸ï¼å°libBaiduMapSDK_vX_X_X.soæ·è´å°libs\armeabi
ç®å½ä¸ï¼æ·è´å®æåï¼å¦ä¸æ示ï¼
注ï¼liblocSDK3.soålocSDK_3.1.jar为ç¾åº¦å®ä½SDKæ使ç¨èµæºï¼å¼åè
å¯æ ¹æ®å®é
éæ±èªè¡æ·»å ã
bubuko.com,å¸å¸æ£
2ãå³é®å·¥ç¨å±æ§ï¼å¨Librariesä¸éæ©âAdd External JARsâï¼éæ©baidumapapi_vX_X_X.jarï¼ç¡®å®è¿å
é
置好以ä¸æ¥éª¤ï¼å³å¯ä½¿ç¨ç¾åº¦å°å¾äº
ä¸ãæ¾ç¤ºç¾åº¦å°å¾
1ãå¨androidé
ç½®æ¸
åæ件ä¸AndroidManifest.xmlæ·»å å¼åå¯é¥åæéæé
<application> <meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="å¼åè
key" /> </application>
æéæé
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
2ãå¨xmlå¸å±ä¸æ·»å å°å¾æ§ä»¶
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
?3ãå¨åºç¨ç¨åºå建æ¶åå§åï¼SDKå¼ç¨çå
¨å±åéContext
注æï¼å¨SDKååè½ç»ä»¶ä½¿ç¨ä¹åé½éè¦è°ç¨
SDKInitializer.initialize(getApplicationContext());ï¼å æ¤æ们建议该æ¹æ³æ¾å¨Applicationçåå§åæ¹æ³ä¸
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//å¨ä½¿ç¨SDKåç»ä»¶ä¹ååå§åcontextä¿¡æ¯ï¼ä¼ å
¥ApplicationContext
SDKInitializer.initialize(getApplicationContext());
System.out.println("SDKInitializerä¸åå§å");
}
}
设置èªå®ä¹çapplication为é»è®¤åºç¨
<application
android:name="com.bao.ah.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//å¨ä½¿ç¨SDKåç»ä»¶ä¹ååå§åcontextä¿¡æ¯ï¼ä¼ å
¥ApplicationContext
//注æ该æ¹æ³è¦åsetContentViewæ¹æ³ä¹åå®ç°
//SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
}
}
4ãç¾åº¦å°å¾åºåActivityçå½å¨æç»å®
public class MainActivity extends Activity {
MapView mMapView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//å¨ä½¿ç¨SDKåç»ä»¶ä¹ååå§åcontextä¿¡æ¯ï¼ä¼ å
¥ApplicationContext
//注æ该æ¹æ³è¦åsetContentViewæ¹æ³ä¹åå®ç°
//SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
//è·åå°å¾æ§ä»¶å¼ç¨
mMapView = (MapView) findViewById(R.id.bmapView);
}
@Override
protected void onDestroy() {
super.onDestroy();
//å¨activityæ§è¡onDestroyæ¶æ§è¡mMapView.onDestroy()ï¼å®ç°å°å¾çå½å¨æ管ç
mMapView.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
//å¨activityæ§è¡onResumeæ¶æ§è¡mMapView. onResume ()ï¼å®ç°å°å¾çå½å¨æ管ç
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
//å¨activityæ§è¡onPauseæ¶æ§è¡mMapView. onPause ()ï¼å®ç°å°å¾çå½å¨æ管ç
mMapView.onPause();
}
}