I am trying to make it so a MapView zooms to a current location based on a GeoPoint. I am setting the location using the geo fix command in telnet. My problem is that when I first input a location using geo fix my code will correctly navigate to a location on the map. If I try to set another location using geo fix however it d开发者_Python百科oes not update. Here is the code to update:
public void updateLocation(Location loc) {
p = new GeoPoint((int)(loc.getLongitude() * 1E6),(int)(loc.getLatitude() * 1E6));
mc = mapView.getController();
mc.animateTo(p);
}
and here is my code to call the update:
LocationListener onLocationChange=new LocationListener() {
public void onLocationChanged(Location location) {
updateLocation(location);
}
etc...
I have the following in onResume():
super.onResume();
myLocationManager.requestLocationUpdates("gps", 0, 200, onLocationChange);
The points I am trying to geo fix to are far enough apart to meet the minimum distance requirement. Anyone have any ideas of what I'm missing?
Call mapView.invalidate();
(see View:invalidate()) or mapView.postInvalidate();
(see View:postInvalidate()), depending on if it runs on UI thread or not, after
mc.animateTo(p);
Assuming your MapActivity implements LocationListener, then change
myLocationManager.requestLocationUpdates("gps", 0, 200, onLocationChange);
to
myLocationManager.requestLocationUpdates("gps", 0, 200, this);
'this' holds the location listener
精彩评论