我相信你需要做的就是打电话mapView.invalidate()
,我设置的地图和你的有点不同,我复制了下面的代码以供参考:
LocationManager jLocManager;
MapController mController;
GeoPoint geoP;
MapView mapView;
MyLocationOverlay myLocOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
try {
JJMapsInitialize();
}catch(Exception e){
Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
}
myLocOverlay = new MyLocationOverlay(this, mapView);
myLocOverlay.enableMyLocation();
mapView.getOverlays().add(myLocOverlay);
}
public void findMyLocation() {
LocationManager jLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// 35000 is 35 seconds to find location && 10 is the minimum distance in meters
jLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, this.jLocListener);
jLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 3000, 10, this.jLocListener);
}
private void JJMapsInitialize() {
try {
mapView = (MapView) findViewById(R.id.mapview);
mapView.displayZoomControls(true);
mapView.setBuiltInZoomControls(true);
mController.animateTo(geoP);
mController.setZoom(10);
mapView.invalidate();
} catch(Exception e) {
Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
}
try {
findMyLocation();
} catch (Exception e) {
Log.e("findMyLocation", "FAILED: " + e.getMessage());
}
}
正如你所看到的,我调用了初始化方法,在该方法中我使用控件设置了我MapView
的控件,使其无效,然后添加我的叠加层。
编辑
jLocListener
只是我的LocationListener()
- 我的名字以“j”开头,所以我通常在命名约定中使用我的首字母或两个首字母。
public LocationListener jLocListener = new LocationListener() {
//class findMe implements LocationListener {
public void onLocationChanged(Location location) {
try {
lat = location.getLatitude();
lon = location.getLongitude();
} catch (Exception e) {
Log.e("onLocationChanged", "FAILED: " + e.getMessage());
}
}
public void onProviderDisabled(String provider) {
Log.i("LocationListener", "onProviderDisabled");
}
public void onProviderEnabled(String provider) {
Log.i("LocationListener", "onProviderEnabled");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.i("LocationListener", "onStatusChanged");
}
};