0

I am using osmdroid to display a map from MAPNIK and set the center of the map at aspecific location the applcation works with no errors, but the map is center at a location that is far from the point that I especified in the code, I set the location(lat and long) from the code I needed that way I don't want to send them from the DDMS, My code is:

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);

and I also have this error in the emulator:

[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 and as I said it is in the console labled: DDMS, so the app works fine and does not crash

4

1 回答 1

1

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

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

希望有帮助!

于 2012-08-20T23:56:27.420 回答