title: Determine user location on osm maps
body: <p>I am working on an android application that determines user location in osm maps. I am being able to show user location on the map, but if the location change the whole map is reloaded, what’s wrong with that? Also how I can increase the accuracy of the user location? And how can I make a circle that increase and decrease according to the accuracy(as shown in Google one)?</p>
  
  <p>code :</p>
  
  <pre><code>public class OsmDemoActivity extends Activity implements LocationListener, 
      MapViewConstants 
  {  
  private MapView mMapView; 
  private MapController mapController; 
  private LocationManager mLocMgr; 
  private ItemizedOverlay&lt;OverlayItem&gt; mMyLocationOverlay; 
  private ResourceProxy mResourceProxy; 
  
  ArrayList&lt;OverlayItem&gt; items;
  
  @Override 
  public void onCreate(Bundle savedInstanceState) 
  { 
      super.onCreate(savedInstanceState); 
      mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext()); 
      setContentView(R.layout.main); 
      //mMapView.setUseDataConnection(false);
      initilaizeMap();
      //addOverlay(); 
      mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE); 
      mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);      
  } 
  
  public void initilaizeMap()
  {
      mMapView = (MapView) this.findViewById(R.id.mapView); 
      mMapView.setTileSource(TileSourceFactory.MAPNIK); 
  
  
  
      //mMapView.setUseDataConnection(false);
  
  
  
      mMapView.setBuiltInZoomControls(true); 
      mMapView.setMultiTouchControls(true); 
      mapController = this.mMapView.getController(); 
      mapController.setZoom(15); 
      mapController.setCenter(new GeoPoint(15.610762,32.540345));
  
  
      /*
      final MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mMapView, 
              mResourceProxy); 
      myLocationOverlay.enableMyLocation();
      //myLocationOverlay.disableMyLocation(); // not on by default 
      myLocationOverlay.disableCompass(); 
      myLocationOverlay.disableFollowLocation(); 
      myLocationOverlay.setDrawAccuracyEnabled(true); 
      myLocationOverlay.runOnFirstFix(new Runnable() { 
          public void run() { 
              mapController.animateTo(myLocationOverlay 
                      .getMyLocation()); 
          } 
      }); 
      //ArrayList&lt;OverlayItem&gt; mOsmOverlays;
      //mOsmOverlays.add(myLocationOverlay); 
      */
  }
  
  public void addOverlay()
  {
      GeoPoint point2 = new GeoPoint(53554070, -2959520); // centre map here 
      GeoPoint point3 = new GeoPoint(53554070 + 1000, -2959520 + 1000); // icon goes here 
      GeoPoint point4 = new GeoPoint(15.610844, 32.540045);
      GeoPoint point5 = new GeoPoint(15610844 + 40, 32540045 + 40);
      GeoPoint point6 = new GeoPoint(15610844 + 50, 32540045 + 50);
      GeoPoint point7 = new GeoPoint(15610844 + 10, 32540045 +10);
      mapController.setCenter(point4);
      items = new ArrayList&lt;OverlayItem&gt;(); 
      // Put overlay icon a little way from map center 
      items.add(new OverlayItem("Here5", "SampleDescription", point5)); 
      items.add(new OverlayItem("Here6", "SampleDescription", point6));
      items.add(new OverlayItem("Here7", "SampleDescription", point7));
      /* OnTapListener for the Markers, shows a simple Toast. */ 
      this.mMyLocationOverlay = new ItemizedIconOverlay&lt;OverlayItem&gt;(items, 
              new ItemizedIconOverlay.OnItemGestureListener&lt;OverlayItem&gt;() { 
                  @Override 
                  public boolean onItemSingleTapUp(final int index, 
                          final OverlayItem item) { 
                      Toast.makeText( 
                              OsmDemoActivity.this, 
                              "Item onItemSingleTapUp '" + item.mTitle, Toast.LENGTH_LONG).show(); 
                      return true; // We 'handled' this event. 
                  } 
                  @Override 
                  public boolean onItemLongPress(final int index, 
                          final OverlayItem item) { 
                      Toast.makeText( 
                              OsmDemoActivity.this,  
                              "Item onItemLongPress '" + item.mTitle ,Toast.LENGTH_LONG).show(); 
                      return false; 
                  } 
              }, mResourceProxy); 
      this.mMapView.getOverlays().add(this.mMyLocationOverlay); 
      mMapView.invalidate(); 
  }
  
  public void displayLocation(GeoPoint loc)
  {
      mapController.setCenter(loc);
      items = new ArrayList&lt;OverlayItem&gt;(); 
      // Put overlay icon a little way from map center
      items.add(new OverlayItem("Here u r", "SampleDescription", loc));
      /* OnTapListener for the Markers, shows a simple Toast. */ 
      this.mMyLocationOverlay = new ItemizedIconOverlay&lt;OverlayItem&gt;(items, 
              new ItemizedIconOverlay.OnItemGestureListener&lt;OverlayItem&gt;() { 
                  @Override 
                  public boolean onItemSingleTapUp(final int index, 
                          final OverlayItem item) { 
                      Toast.makeText( 
                              OsmDemoActivity.this, 
                              "Item onItemSingleTapUp '" + item.mTitle, Toast.LENGTH_LONG).show(); 
                      return true; // We 'handled' this event. 
                  } 
                  @Override 
                  public boolean onItemLongPress(final int index, 
                          final OverlayItem item) { 
                      Toast.makeText( 
                              OsmDemoActivity.this,  
                              "Item onItemLongPress '" + item.mTitle ,Toast.LENGTH_LONG).show(); 
                      return false; 
                  } 
              }, mResourceProxy); 
      mMapView.getOverlays().clear();
      this.mMapView.getOverlays().add(this.mMyLocationOverlay); 
      //mMapView.invalidate();
  }
  
  public void onLocationChanged(Location location)
  { 
      int lat = (int) (location.getLatitude() * 1E6); 
      int lng = (int) (location.getLongitude() * 1E6); 
      GeoPoint gpt = new GeoPoint(lat, lng); 
      //mapController.setCenter(gpt); 
      //mMapView.invalidate();
      displayLocation(gpt);
  } 
  
      @Override 
      public void onProviderDisabled(String arg0) {} 
      @Override 
      public void onProviderEnabled(String provider) {} 
      @Override 
      public void onStatusChanged(String provider, int status, Bundle extras) {} 
  
  }
  </code></pre>