IMPLEMENT PUSHIN ON GOOGLE MAP

Monaj Singh

Total Post:41

Points:287
Posted by  Monaj Singh
 466  View(s)
Ratings:
Rate this:
I am implementing to show the particular location on the map and on the same location i want to put the pushpin notification. I have tried to sove this in my way using  below code but it showing nullpointer exception, please suggest me the right solution to implement the markers
public class MapDemoActivity extends MapActivity {
 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) 
        {
            super.draw(canvas, mapView, shadow);                   

            //---translate the GeoPoint to screen pixels---
            Point screenPts = new Point();
            mapView.getProjection().toPixels(p, screenPts);

            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(
                getResources(), R.drawable.pushpin);            
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
            return true;
        }
    } 

 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapView);

        mapView.setBuiltInZoomControls(true);
        mc.animateTo(p);
        mc.setZoom(17); 

        //---Add a location marker---
        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;
}

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!