3

I want to find current location and make marker on that location. plz tell me

if any example is there then please tell me..

like this

enter image description here

Thanks in Advance...

Patel
  • 43
  • 1
  • 5

2 Answers2

1

for find current location use gps. You can get more examples for that and for marker see this links. https://github.com/jgilfelt/android-mapviewballoons

kalpana c
  • 2,739
  • 3
  • 27
  • 47
  • using your link i have to pass latitude and longitude by manually but i want this by automatically .? – Patel Dec 10 '11 at 09:30
  • yes using GPS_PROVIDER you can get latitude and longitude to pass. and you can try to modifiying that code – kalpana c Dec 10 '11 at 09:57
0

Here we have few simple steps

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.pin);            
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
            return true;
        }
    } 

after abv code call your marker

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

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

    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    List<Address> addresses = null;
    try {
        addresses = geocoder.getFromLocationName(getIntent().getStringExtra("address"), 1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Address address = addresses.get(0);   
    double lng  = address.getLongitude();
    double lat  = address.getLatitude();   



    p = new GeoPoint(
        (int) (lat * 1E6), 
        (int) (lng * 1E6));

    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();
    mapView.invalidate();
 }

Hope I have cleared you some what. Keep smiling :)

Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121