title: Android:Google map current location and other marker points
body: <p>I'm developing an android Google map app. How to create a current location ,balloon overlay and other marker location points.</p>
  
  <p>I am creating Other marker location points in (CustomMap.java)</p>
  
  <p>Here I want to current location also.Please help me</p>
  
  <p><strong>CustomMap.java</strong></p>
  
  <pre><code> public class CustomMap extends MapActivity implements LocationListener {
  
  MapView mapView;
  List&lt;Overlay&gt; mapOverlays;
  Drawable drawable;
  Drawable drawable2;
  CustomItemizedOverlay&lt;CustomOverlayItem&gt; itemizedOverlay;
  CustomItemizedOverlay&lt;CustomOverlayItem&gt; itemizedOverlay2;
  double longitude;
  double latitude;
  
  long start;
  long stop;
  int x, y;
  int lati = 0; 
  int longit = 0;
  GeoPoint touchedPoint;
  public boolean overlay_status=false;
  
   /** Called when the activity is first created. */
      @Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      // making it full screen
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.activity_custom_map);
  
      mapView = (MapView) findViewById(R.id.mapview);
      mapView.setBuiltInZoomControls(true);
  
      mapOverlays = mapView.getOverlays();
  
      // first overlay
      drawable = getResources().getDrawable(R.drawable.marker);
      itemizedOverlay = new CustomItemizedOverlay&lt;CustomOverlayItem&gt;(drawable, mapView);
  
      //first overlay in first pinpoint
      GeoPoint point = new GeoPoint((int)(13.0094444*1E6),(int)(77.5508333*1E6));
      CustomOverlayItem overlayItem = new CustomOverlayItem(point, "ISKCON Temple Bangalore(1997)", 
              "(ISKCON Temple, Chord Rd, Mahalakshmipuram Layout, Nagapura, Bangalore, Karnataka, India)", 
              "http://www.iskcon-bda.org/data/HKH.jpg");
      itemizedOverlay.addOverlay(overlayItem);
  
      //first overlay in second pinpoint
      GeoPoint point2 = new GeoPoint((int)(12.8008*1E6),(int)(77.5756*1E6));
      CustomOverlayItem overlayItem2 = new CustomOverlayItem(point2, "Bannerghatta National Park", 
              "(Bannerghatta Biological Park is carved out of the Bannerghatta National Park in the year 2002)", 
              "http://www.google.co.in/imgres?imgurl=http://travel.sulekha.com/" +
              "india/karnataka/bangalore/photos/bannerghatta-national-park-25.jpg&amp;imgrefurl=http://travel.sulekha.com/" +
              "a-visit-to-bannerghatta-national-park_bangalore-travelogue-3541.htm&amp;h=194&amp;w=259&amp;sz=1&amp;tbnid=K5TNPwXHgihgRM:&amp;tbnh=" +
              "119&amp;tbnw=160&amp;zoom=1&amp;usg=__MFNGL1C2InXP7jw7XmEi4ym45NY=&amp;docid=d78iF3T5ditWeM&amp;itg=1&amp;hl=en&amp;sa=X&amp;ei=" +
              "CpwQUdOmHIPUrQe0m4H4Bg&amp;sqi=2&amp;ved=0CHwQ_B0wCw");        
      itemizedOverlay.addOverlay(overlayItem2);
  
      mapOverlays.add(itemizedOverlay);
  
      // second overlay
      drawable2 = getResources().getDrawable(R.drawable.marker2);
      itemizedOverlay2 = new CustomItemizedOverlay&lt;CustomOverlayItem&gt;(drawable2, mapView);
  
      //second overlay in third pinpoint
      GeoPoint point3 = new GeoPoint((int)(12.8339956*1E6),(int)(77.4009816*1E6));
      CustomOverlayItem overlayItem3 = new CustomOverlayItem(point3, "Wonderla Bangalore(2005)", 
              "(Wonderla is an amusement park located near Bidadi, 28 kilometres Bangalore, spanning 82 acres of land)",
              "http://www.google.co.in/imgres?imgurl=http://www.yohyoh.com/places-tourism/pictures/wb3.jpg&amp;imgrefurl=http://" +
              "www.yohyoh.com/places-tourism/view.php/popular-tours/Karnataka/Bangalore/wonderla-bangalore/561/8192987807&amp;h=" +
              "194&amp;w=259&amp;sz=1&amp;tbnid=RoLC5gzRHP6VSM:&amp;tbnh=160&amp;tbnw=213&amp;zoom=1&amp;usg=__ShDQAmQ0zjQaKbsy0A63BokHAmk=" +
              "&amp;docid=J1aN09WXjvHw4M&amp;itg=1&amp;hl=en&amp;sa=X&amp;ei=Sp0QUbvIEMHjrAfTy4GgBA&amp;ved=0CNMBEPwdMAo");
      itemizedOverlay2.addOverlay(overlayItem3);
  
      //second overlay in third pinpoint
      GeoPoint point4 = new GeoPoint((int)(12.8385923*1E6),(int)(77.661710599*1E6));
      CustomOverlayItem overlayItem4 = new CustomOverlayItem(point4, "Wipro Technologies,Bangalore", 
              "(Wipro Technologies, Electronics City Phase 1, Electronics City, Bangalore, Karnataka 560100, India)", 
              "http://www.electronic-city.in/companies/profile/wipro/wipro-electronic-city.jpg");     
      itemizedOverlay2.addOverlay(overlayItem4);
  
      mapOverlays.add(itemizedOverlay2);
  
  
  
      // Getting LocationManager object from System Service LOCATION_SERVICE
      LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  
      // Creating a criteria object to retrieve provider
      Criteria criteria = new Criteria();
  
      criteria.setAccuracy(Criteria.ACCURACY_FINE);
  
      // Getting the name of the best provider
      String provider = locationManager.getBestProvider(criteria, true);
  
      // Getting Current Location
      Location location = locationManager.getLastKnownLocation(provider);
  
      if(location!=null){
          onLocationChanged(location);
      }
  
      locationManager.requestLocationUpdates(provider, 20000, 0, this);
  
      String address = "";
      Geocoder geoCoder = new Geocoder(
              getBaseContext(), Locale.getDefault());
  
     latitude = location.getLatitude();
  
      // Getting longitude
      longitude = location.getLongitude();
  
      // Creating an instance of GeoPoint corresponding to latitude and longitude
      GeoPoint point5 = new GeoPoint((int)(latitude * 1E6), (int)(longitude*1E6));
  
      try {
          List&lt;Address&gt; addresses = geoCoder.getFromLocation(
              point.getLatitudeE6()  / 1E6, 
              point.getLongitudeE6() / 1E6, 1);
  
              if (addresses.size() &gt; 0) {
                  for (int index = 0; index &lt; addresses.get(0).getMaxAddressLineIndex(); index++)
                      address += addresses.get(0).getAddressLine(index) + " ";
              }
              tvLocation.setText("Address :" +  address  );
      }
      catch (IOException e) {                
          e.printStackTrace();
      }
  
  
      drawable = getResources().getDrawable(R.drawable.url);
      itemizedOverlay = new CustomItemizedOverlay&lt;CustomOverlayItem&gt;(drawable, mapView);
  
      mapView.getOverlays().add(itemizedOverlay);
      itemizedOverlay.runOnFirstFix(new Runnable() {
       @Override
      public void run() {
       // TODO Auto-generated method stub
       mapView.getOverlays().add(itemizedOverlay);
       }
       });
      MapController mapController = mapView.getController();
  
      // Locating the Geographical point in the Map
      mapController.animateTo(point5);
      itemizedOverlay.enableMyLocation();
       mapView.postInvalidate();
      // Getting list of overlays available in the map
      List&lt;Overlay&gt; mapOverlays = mapView.getOverlays();
  
      CustomOverlayItem currentLocation = new CustomOverlayItem(point, "Current Location", "Latitude : " + latitude + ", Longitude:" + longitude, null);
  
      // Adding the mark to the overlay
      itemizedOverlay.addOverlay(currentLocation);
  
      // Clear Existing overlays in the map
      mapOverlays.clear();
      mapOverlays.add(itemizedOverlay);
  
  
  
      if (savedInstanceState == null) {
  
      //Contains Displaying the pinpoint
      final MapController mc = mapView.getController();
      mc.animateTo(point);
      mc.setZoom(16);
      }else {
  
          // example restoring focused state of overlays
          int focused;
          focused = savedInstanceState.getInt("focused_1", -1);
          if (focused &gt;= 0) {
              itemizedOverlay.setFocus(itemizedOverlay.getItem(focused));
          }
          focused = savedInstanceState.getInt("focused_2", -1);
          if (focused &gt;= 0) {
              itemizedOverlay2.setFocus(itemizedOverlay2.getItem(focused));
          }
  
      }
  
  
  
  
      Touchy t = new Touchy();
      mapOverlays = mapView.getOverlays();
      mapOverlays.add(t);
  }
  
  @Override
  protected boolean isRouteDisplayed() {
      return false;
  }
  @Override
  protected void onSaveInstanceState(Bundle outState) {
  
      // example saving focused state of overlays
      if (itemizedOverlay.getFocus() != null) outState.putInt("focused_1", itemizedOverlay.getLastFocusedIndex());
      if (itemizedOverlay2.getFocus() != null) outState.putInt("focused_2", itemizedOverlay2.getLastFocusedIndex());
      super.onSaveInstanceState(outState);
  
  }
  
  //Contains creating the option menu items 
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      menu.add(0, 0, 1, "Remove Overlay");
      menu.add(0, 1, 1, "set Overlay");
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.drawable.home_menu, menu);
      return true;
  }
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
      if(overlay_status==false)
      {
       menu.findItem(1).setVisible(false);
       menu.findItem(0).setVisible(true);
  
      //overlay_status=true;
      }
      else
      {
           menu.findItem(0).setVisible(false);
           menu.findItem(1).setVisible(true);
  
          // overlay_status=false;
      }
   return super.onPrepareOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
      case R.id.home1:
           finish();
          return true;
      case 0:
  
          //Toast.makeText(getApplicationContext(), "remove overlay ", Toast.LENGTH_SHORT).show();
  
          // example hiding balloon before removing overlay
                      if (itemizedOverlay.getFocus() != null) {
                          itemizedOverlay.hideBalloon();
                      }
                      mapOverlays.remove(itemizedOverlay);
                      mapView.invalidate();
                      overlay_status=true;
                  return true;    
      case 1:
  
  
          Toast.makeText(getApplicationContext(), "set overlay ", Toast.LENGTH_SHORT).show();
          if (itemizedOverlay.getFocus() != null) {
              itemizedOverlay.getBalloonBottomOffset();
          }
          mapOverlays.add(itemizedOverlay);
               mapView.bringToFront();
  
               overlay_status=false;
               return true;
      default:
          return super.onOptionsItemSelected(item);
  }
  
  }
  
  class Touchy extends Overlay{
      List&lt;Address&gt; address;
      String display = "";
      String display1;
      @SuppressWarnings({ "deprecation" })
      public boolean onTouchEvent(MotionEvent e,MapView m){
          if(e.getAction() == MotionEvent.ACTION_DOWN){
              start = e.getEventTime();
              x = (int)e.getX();
              y = (int)e.getY();
              touchedPoint = mapView.getProjection().fromPixels(x, y);
              Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());    
              try{
                  address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() / 1E6, touchedPoint.getLongitudeE6() / 1E6, 1);
                  if(address.size() &gt; 0){
  
                      for(int i = 0; i&lt;address.get(0).getMaxAddressLineIndex(); i++){
                          display +=address.get(0).getAddressLine(i) + "\n";
                      }
  
                      Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG).show();
  
                  }
  
              }catch(IOException e1){
  
              }
              finally
              {
                  display1=display;
                  display=" ";
              }
  
              }
          if(e.getAction() == MotionEvent.ACTION_UP){
              stop = e.getEventTime();
          }
  
      /**contains the creating a Alert Dialog Box (place apinpoint, get address, Toggle View)
       * In Dialog Box Maximum three buttens
       */
      if(stop - start &gt; 1000){
          AlertDialog alert = new AlertDialog.Builder(CustomMap.this).create();
          alert.setTitle("pick an Option");
          alert.setMessage("I told to pick an option");
  
          alert.setButton("place a pinpoint", new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  CustomOverlayItem overlayItem = new CustomOverlayItem(touchedPoint,"Address:",display1, display1);
   //                 SimpleItemizedOverlay itemizedOverlay = new SimpleItemizedOverlay(drawable, mapView);
                  CustomItemizedOverlay&lt;CustomOverlayItem&gt; itemOverlay = new CustomItemizedOverlay&lt;CustomOverlayItem&gt;(drawable, mapView);
   //                 CustomPinpoint custom = new CustomPinpoint(drawable, CustomMap.this);
   //                 custom.insertPinpoint(overlayItem);
                  itemOverlay.insertPinpoint(overlayItem);
                  itemOverlay.addOverlay(overlayItem);
                  mapOverlays.add(itemOverlay);
              }
          });
  
          alert.setButton2("get address", new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
  
              Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());    
                  try{
                      List&lt;Address&gt; address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() / 1E6, touchedPoint.getLongitudeE6() / 1E6, 1);
                      if(address.size() &gt; 0){
                          String display = "";
                          for(int i = 0; i&lt;address.get(0).getMaxAddressLineIndex(); i++){
                              display +=address.get(0).getAddressLine(i) + "\n";
                          }
                          Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG).show();
  
                      }
  
                  }catch(IOException e){
  
                  }
              }
          });
  
          alert.setButton3("Toggle View", new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
  
                  if(mapView.isSatellite()){
                      mapView.setSatellite(false);
                      mapView.setStreetView(true);
                  }else{ 
                      mapView.setStreetView(false);
                      mapView.setSatellite(true);
                  }
  
              }
          });
  
  
          alert.show();
          return true;
      }
      return false;
  
  }
  
   }
  @Override
  public void onLocationChanged(Location location) {
      lati = (int) (location.getLatitude() * 1E6);
      longit = (int) (location.getLongitude() * 1E6);
      GeoPoint ourLocation = new GeoPoint(lati, longit);
      OverlayItem overlayItem = new OverlayItem(ourLocation, "What's up?", "2nd String");
      CustomPinpoint custom = new CustomPinpoint(drawable, CustomMap.this);
      custom.insertPinpoint(overlayItem);
      mapOverlays.add(custom);
  
  }
  
  @Override
  public void onProviderDisabled(String provider) {
  
  }
  
  @Override
  public void onProviderEnabled(String provider) {
  
  }
  
  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
  
  }
  
   }
  </code></pre>