使用MapView异常:java.lang.SecurityException: Requires ACCESS_FINE_LOCATION or ACCESS
09-07 15:18:30.153: ERROR/AndroidRuntime(254): Uncaught handler: thread main exiting due to uncaught exception
09-07 15:18:30.208: ERROR/AndroidRuntime(254): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.joyband.demo/com.joyband.demo.AndroidDemo1}: java.lang.SecurityException: Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Looper.loop(Looper.java:123)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.main(ActivityThread.java:4338)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at java.lang.reflect.Method.invoke(Method.java:521)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at dalvik.system.NativeStart.main(Native Method)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): Caused by: java.lang.SecurityException: Requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Parcel.readException(Parcel.java:1218)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.os.Parcel.readException(Parcel.java:1206)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.location.ILocationManager$Stub$Proxy.getLastKnownLocation(ILocationManager.java:778)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.location.LocationManager.getLastKnownLocation(LocationManager.java:944)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.joyband.demo.AndroidDemo1.getLocation(AndroidDemo1.java:41)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at com.joyband.demo.AndroidDemo1.onCreate(AndroidDemo1.java:29)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
09-07 15:18:30.208: ERROR/AndroidRuntime(254): ... 11 more
我的代码:
public class AndroidDemo1 extends MapActivity {
private MapView mapView;
private MapController mapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);//多点触摸
mapView.setSatellite(true);
mapController = mapView.getController();
mapController.setZoom(15);
mapController.animateTo(getLocation());
Log.i("AndroidDemo1", "MapView 启动");
}
@Override
public boolean isRouteDisplayed() {
return false;
}
private GeoPoint getLocation(){
LocationManager locationMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
return new GeoPoint((int)(location.getLatitude()*1e6),(int)(location.getLongitude()*1e6));
}
}
我的AndroidManifest.xml文件配置:
<?xml version="1.0" encoding="utf-8"?>
package="com.joyband.demo"
android:versionCode="1"
android:versionName="1.0">
android:label="@string/app_name">
不知道什么原因,请哪位指点一下?