Hi friends!
In my application I tried to search diff map location using diff lat and long. First time the application show the map but wen i change the lat long and try to invalidate the mapview using diff lat long, map is not refreshed.
Below is my code please have a look and suggest accordingly:
//Source code
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.main);
infoTextView = (TextView) findViewById(R.id.infoTextView);
// Finding Current Location
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
1l, 1l, this);
Location location = locationManager.getLastKnownLocation("gps");
// mock location by hard-code if DDMS has not sent a fake loc to the emulator.
if (location == null) {
lat = 13.6972 * 1E6;
lng = 100.5150 * 1E6;
} else { // get real location if can retrieve the location sent by DDMS or GPS
lat = location.getLatitude() * 1E6;
lng = location.getLongitude() * 1E6;
}
setGPSLocation(lat, lng);
}
//This is the function which I am calling with different lat and long
public void setGPSLocation(Double lati, Double longi)
{
lat = lati;
lng = longi;
System.out.println("Latitude :"+ lat +" Longitude :"+lng);
// Prepare text being shown
String tmpLoc = LOC_INFO_TEMPLATE;
tmpLoc = tmpLoc.replace("lg", String.valueOf(lng));
tmpLoc = tmpLoc.replace("lt", String.valueOf(lat));
infoTextView.setText(tmpLoc);
// Setup Zoom/Hide Buttons
linearLayout = (LinearLayout) findViewById(R.id.zoomview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.invalidate();
mapView.setBuiltInZoomControls(true); //new by me
mapView.setSatellite(true); // Set satellite view
mZoom = (ZoomControls) mapView.getZoomControls();
linearLayout.addView(mZoom);
// Setup Marker
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new MyItemizedOverlay(drawable);
GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
OverlayItem overlayitem = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
// Centralize Current Location
myMapController = mapView.getController();
myMapController.setZoom(DEFAULT_ZOOM_NUM);
centerlizeCurrentLocation(point);
}
Any suggest is truly appreciable.