Hello,
I am trying to develop a simple application. I am trying to show a particular place on Map along with providing the facility to zoomin and zoom out. I have been able to zoomin and zoomout for the map by creating two buttons and then setting their OnClickListener. Now, Once a user click button Search, I want that place to be marked on the marked with a zoom level of 15. Further, once the place has been marked on the map, I still want the zoom in and zoom out button to work as they were working before. Note that I have been working on the same screen always.
This is my main activity:
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class SearchMap extends MapActivity {
/** Called when the activity is first created. */
MapView mapView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.home);
//Setting the Event Listener for zoomin Button
Button zoomin = (Button) findViewById(R.id.zoomin);
zoomin.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
mapView = (MapView) findViewById(R.id.map_view);
mapView.getController().zoomTo(mapView.getZoomLevel() + 1);
}
});
//Setting the Event Listener for zoomout Button
Button zoomout = (Button) findViewById(R.id.zoomout);
zoomout.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
mapView = (MapView) findViewById(R.id.map_view);
mapView.getController().zoomTo(mapView.getZoomLevel() - 1);
}
});
//Setting the Event Listener for Search Button
Button searchButton = (Button) findViewById(R.id.searchBtn);
searchButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
EditText searchText = (EditText) findViewById(R.id.searchTxt);
String s = searchText.getText().toString();
mapView = (MapView) findViewById(R.id.map_view);
mapView.createOverlayController().add(new MyOverlay(mapView),true);
}
});
}
}
This is my overlay class:
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Point;
public class MyOverlay extends Overlay {
private Bitmap bubbleIcon, shadowIcon;
private MapView mapView;
public MyOverlay(MapView mapView) {
bubbleIcon = BitmapFactory.decodeResource(mapView.getResources(),R.drawable.bubble);
shadowIcon = BitmapFactory.decodeResource(mapView.getResources(),R.drawable.shadow);
this.mapView = mapView;
}
@Override
public void draw(Canvas canvas, PixelCalculator pixelCalculator, boolean b) {
drawMapLocations(canvas, pixelCalculator, b);
}
private void drawMapLocations(Canvas canvas, PixelCalculator pixelCalculator, boolean b) {
Point point = new Point((int) (37.416402 * 1000000), (int)(-122.025078 * 1000000));
int[] screenCoords = new int[2];
pixelCalculator.getPointXY(point, screenCoords);
if (b) {
// Only offset the shadow in the y-axis as the shadow is angled so the base is at x=0;
canvas.drawBitmap(shadowIcon, screenCoords[0], screenCoords[1] - shadowIcon.height(),null);
} else {
canvas.drawBitmap(bubbleIcon, screenCoords[0] - bubbleIcon.width()/2, screenCoords[1] - bubbleIcon.height(),null);
}
}
}
The problem I am facing is this: Once the user click search button and the place has been marked, the button zoomin and zoomout stops working. I can see that the mapview tries to zoomin / zoomout but somehow the overlay tries the view to be what it creates after once the user hits the search button. I believe I need to get access to Overlay controller and then get the current zoom in ./ zoom out of the overlay and then dynamically bind the onClickListener for the zoomin/zoom out button based to the mapview controller/overlay controller based on whether the user has clicked the search button once or not. I would appreciate if any one can comment on this and give me pointers to proceed further.

