Android使用百度地图定位,记录运动轨迹
- 将百度地图的jar包和.so文件拷贝到libs文件夹下
- 在AndroidManifest.xml文件中添加权限
- 在application子节点中添加
<meta-data android:name ="com.baidu.lbsapi.API_KEY" android:value ="lsgZtdSE280wRIWDQDF2VGMt" />
- 添加必要的权限
<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" /> <uses-permission android:name= "android.permission.ACCESS_FINE_LOCATION" > </uses-permission > <uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE" > </uses-permission >
- 在使用了xml中
com.baidu.mapapi.map.MapView
控件的对应的activity中添加属性<activity android:name="com.panmin.gpstest.MainActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" >
- 添加service服务
<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote" />
- 在application子节点中添加
- xml中控件的添加
<com.baidu.mapapi.map.MapView android:id="@+id/bmapsView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" />
- activity中初始化地图,在setContentView(R.layout. activity_main );之前初始化先
SDKInitializer.initialize(getApplicationContext());
再设置
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
防止屏幕关闭。