Android 位置不准确,正在DDMS中获取异常
我正在使用osmdroid显示来自MAPNIK的地图,并将地图中心设置在特定位置 该应用程序工作正常,没有错误,但地图的中心位置远离我在代码中指定的点,我根据我需要的代码设置了位置(lat和long),我不想从DDMS发送它们,我的代码是:Android 位置不准确,正在DDMS中获取异常,android,mapping,location,emulation,Android,Mapping,Location,Emulation,我正在使用osmdroid显示来自MAPNIK的地图,并将地图中心设置在特定位置 该应用程序工作正常,没有错误,但地图的中心位置远离我在代码中指定的点,我根据我需要的代码设置了位置(lat和long),我不想从DDMS发送它们,我的代码是: Double latitude = 15.610793; Double longitude = 32.540152; int lat = (int) (latitude * 1E6); int lng = (int) (longitude * 1E6);
Double latitude = 15.610793;
Double longitude = 32.540152;
int lat = (int) (latitude * 1E6);
int lng = (int) (longitude * 1E6);
GeoPoint myPoint = new GeoPoint(lat, lng);
// show first message
Toast toast = Toast.makeText(getBaseContext(),
"latitude is :"+lat+"lng is: "+lng, Toast.LENGTH_LONG);
toast.show();
mapView = (MapView) this.findViewById(R.id.mapView);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapController = mapView.getController();
mapController.setCenter(myPoint);
mapController.setZoom(15);
我在模拟器中也有这个错误:
[2012-06-16 00:05:21 - ddms] null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:573)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:672)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
[2012-06-16 00:05:21 - ddms] null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:573)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:672)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
sory I ment error not exception,正如我所说,它位于控制台中,标签为:DDMS,因此应用程序工作正常,不会崩溃,我遇到了类似的问题。尝试颠倒以下语句的顺序:
mapController.setCenter(myPoint);
mapController.setZoom(15);
希望有帮助 我还注意到,当我用google API在emulator中测试它时,位置是准确的,我不知道为什么?我想你必须使用google API才能使用MapView。我说我使用的是osmdroid API,这意味着我不需要GAPI