Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:13:48+00:00 2026-06-04T00:13:48+00:00

I am working on an android application that determines user location in osm maps.

  • 0

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)?

code :

public class OsmDemoActivity extends Activity implements LocationListener, 
    MapViewConstants 
{  
private MapView mMapView; 
private MapController mapController; 
private LocationManager mLocMgr; 
private ItemizedOverlay<OverlayItem> mMyLocationOverlay; 
private ResourceProxy mResourceProxy; 

ArrayList<OverlayItem> 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<OverlayItem> 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<OverlayItem>(); 
    // 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<OverlayItem>(items, 
            new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() { 
                @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<OverlayItem>(); 
    // 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<OverlayItem>(items, 
            new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() { 
                @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) {} 

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:13:51+00:00Added an answer on June 4, 2026 at 12:13 am

    You must use an location change listener
    Maybe this can help you

    Listener:

    package dispatch.driver.osmMaps;
    
    import org.osmdroid.util.GeoPoint;
    
    import android.location.Location;
    import android.location.LocationListener;
    import android.os.Bundle;
    import android.widget.Toast;
    
    public class OsmGeoUpdateHandler implements LocationListener
    {
    
        private OsmMapsActivity mMapActivity;
    
        public OsmGeoUpdateHandler(OsmMapsActivity aMapActivity)
        {
            this.mMapActivity = aMapActivity;
    
        }
    
        @Override
        public void onLocationChanged(Location location)
        {
            Toast.makeText(mMapActivity,
                    "latitude = " + location.getLatitude() * 1e6 + " longitude = " + location.getLongitude() * 1e6,
                    Toast.LENGTH_SHORT).show();
    
            int latitude = (int) (location.getLatitude() * 1E6);
            int longitude = (int) (location.getLongitude() * 1E6);
            GeoPoint point = new GeoPoint(latitude, longitude);
            mMapActivity.updateCarPosition(point);
        }
    
        @Override
        public void onProviderDisabled(String provider)
        {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onProviderEnabled(String provider)
        {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras)
        {
            // TODO Auto-generated method stub
    
        }
    
    }
    

    OsmMapActivity class (how to use listener)

    public class OsmMapsActivity extends Activity
    {
        // final private int MAP_DEFAULT_ZOOM = 14;
        final private double MAP_DEFAULT_LATITUDE = 44.445883;
        final private double MAP_DEFAULT_LONGITUDE = 26.040963;
    
        private MapView mMapView;
        private ResourceProxy mResourceProxy;
        private OsmMapsItemizedOverlay mItemizedOverlay;
        private MyLocationOverlay mMyLocationOverlay;
        private LocationManager locationManager;
        private OverlayItem lastPosition = null;
        private Order mOrder;
        OsmGeoUpdateHandler mUpdateHandler;
        private ArrayList<OverlayItem> mItems = new ArrayList<OverlayItem>();
    
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    
            // Specify the XML layout to use:
            setContentView(R.layout.osmmap);
    
            mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
            mMapView = (MapView) findViewById(R.id.mapview);
    
            // Setup the mapView controller:
            mMapView.setBuiltInZoomControls(true);
            mMapView.setMultiTouchControls(true);
            mMapView.setClickable(true);
            mMapView.setUseDataConnection(false);
            mMapView.setTileSource(TileSourceFactory.MAPNIK);
            mMapView.getController().setZoom(12);
    
    
            /* location manager */
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            mUpdateHandler = new OsmGeoUpdateHandler(this);
            Location location = null;
    
            for (String provider : locationManager.getProviders(true))
            {
                location = locationManager.getLastKnownLocation(provider);
                if (location != null)
                {
                    //location.setLatitude(MAP_DEFAULT_LATITUDE);
                    //location.setLongitude(MAP_DEFAULT_LONGITUDE);
                    locationManager.requestLocationUpdates(provider, 0, 0, mUpdateHandler);
                    break;
                }
            }
    
            //add car position
            if (location == null)
            {
                location = new Location(LocationManager.GPS_PROVIDER);
                location.setLatitude(MAP_DEFAULT_LATITUDE);
                location.setLongitude(MAP_DEFAULT_LONGITUDE);
                updateCarPosition(new GeoPoint(location));
            }
    
        } // end onCreate()
    public void updateCarPosition(GeoPoint aPoint)
        {
            if (mItemizedOverlay == null)
            {
                return;
            }
            OverlayItem overlayItem;
    
            /* remove last position marker */
            removeLastPosition(lastPosition);
    
            overlayItem = new OverlayItem("Center", "Center", (GeoPoint) aPoint);
    
            lastPosition = overlayItem;
    
            mItemizedOverlay.addOverlay(overlayItem);
    
    
            mMapView.getOverlays().add(mItemizedOverlay);
            mMapView.getController().animateTo(aPoint);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're working on an Android application that shows information about parkings on a map.
I am working on Android application that parses a website but I can't seem
I am working on an Android application that requires a user to login before
I am working on an android application that will show an html page that
I am working on an Android application that allows the user to speak into
I am working on an android application that requires multiple views which will overlap
I'm working on an Android application that has several Activities. In it I have
I'm working on an Android application that needs to download an image and display
I am working on an Android application that is required to connect to a
I'm new to Android development and working on an Android application that requires the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.