我正在使用osmdroid从MAPNIK显示地图并将地图中心设置为特定位置 应用程序没有错误,但地图位于远离我在代码中指定的位置的中心位置,我从我需要的代码设置位置(lat和long),我不想这样做从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我的错误也不例外,因为我说它是在控制台中标记:DDMS,所以应用程序工作正常并且不会崩溃
答案 0 :(得分:1)
我遇到了类似的问题。请尝试颠倒以下语句的顺序:
mapController.setCenter(myPoint);
mapController.setZoom(15);
希望有所帮助!