runOnFirstFix not actually running on first location fix
When using a mapView, runOnFirstFix throws a null pointer exception because MyLocOverlay.getMyLocation()
is null. However, this should not happen becuase runOnFirstFix should not run when the location is null. What's going on here?
myLocOverlay.r开发者_运维技巧unOnFirstFix(new Runnable() { public void run() {
map.getController().animateTo(myLocOverlay.getMyLocation());
}
I'm using the emulator to run this code so maybe it's an emulator problem?
I haven't looked into this API, but why don't you wrap that call in an if block that checks if the location is null?
if (myLocOverlay.getMyLocation() != null) {
myLocOverlay.runOnFirstFix(new Runnable() { public void run() {
map.getController().animateTo(myLocOverlay.getMyLocation());
}
}
And more importantly, if you are using the emulator, you need to make sure that you are feeding the emulator gps fixes from the DDMS perspective, this tutorial explains how:
You Are Here: Using GPS and Google Maps in Android
精彩评论