位置不准确,并在 DDMS 中出现异常



我正在使用osmdroid显示来自MAPNIK的地图,并将地图的中心设置为特定位置应用程序工作没有错误,但地图位于远离我在代码中指定的点的位置,我从我需要的代码中设置了位置(纬度和经度),这样我不想从 DDMS 发送它们,我的代码是:

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错误不是异常,正如我所说,它在控制台中标有:DDMS,因此该应用程序运行良好且不会崩溃

我遇到了类似的问题。 尝试反转以下语句的顺序:

mapController.setCenter(myPoint);
mapController.setZoom(15);

希望对您有所帮助!

最新更新