Here I have used google map and an overlay. I have used an image of pushpin to point to the GeoPoint.
I want to set an OnClickListener
event for the push pin. When user touches the pin, I want to toast a message. Below is the code.
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.os.Bundle;
import android.widget.Toast;
public class Googlemap1_6Activity extends MapActivity
{
/** Called when the activity is first created. */
MapView mapView;
MapController mc;
GeoPoint p;
class Mapoverlay extends com.google.android.maps.Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when)
{
// TODO Auto-generated method stub
super.draw(canvas, mapView, shadow, when);
Point screenPts =new Point();
mapView.getProjection().toPixels(p, screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pushpin2);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-26, null);
return true;
}
@Override
public boolean onTap(GeoPoint pl, MapView mapView) {
// TODO Auto-generated method stub
if(pl.equals(p))
{
Toast.makeText(getBaseContext(),
"This is International Airport",
Toast.LENGTH_LONG).show();
}
return super.onTap(pl, mapView);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String lat_coordinates[] ={"27.700556"};
String lng_coordinates[] ={"85.3630"};
Double lat = Double.parseDouble(lat_coordinates[0]);
Double lng = Double.parseDouble(lng_coordinates[0]);
p = new GeoPoint(
(int) (lat*1E6),
(int) (lng*1E6));
mapView = (MapView) findViewById(R.id.mapView);
mc=mapView.getController();
mapView.setBuiltInZoomControls(true);
mc.setZoom(10);
mc.animateTo(p);
Mapoverlay MapOverlay = new Mapoverlay();
List<Overlay> listofOverlays = mapView.getOverlays();
listofOverlays.clear();
listofOverlays.add(MapOverlay);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Thank guys, for you support... In the mean time, i solved my problem so i am posting it here, hope it will help some one else...
Create new class...
Use Below link's Code for that, it may help you.
MapViewBallons
You Override your own Overlay, so you have to handle Tabs yourself. Why not using ItemizedOverlay. Override the onTab(int index) there and you are done. It has also a useful hitTest Method.