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 6084435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:31:16+00:00 2026-05-23T11:31:16+00:00

I am using OSMdroid. I have managed thanks to this post Adding Overlay to

  • 0

I am using OSMdroid.

I have managed thanks to this post Adding Overlay to OSMDROID to creata overlay static item on a specific location.

now I am trying to make the map little bit more dynamic. so when the location change the OverLayItem (which marking the specific location on the map) will update itself also.

this is what I tried to do. the map does update but the OverLayItem doesnt.

code:

package com.test.overlay;

import java.util.ArrayList;
import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.ItemizedOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import org.osmdroid.views.util.constants.MapViewConstants;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class SampleWithMinimapItemizedoverlay extends Activity implements
        LocationListener, MapViewConstants
{

    private MapView mMapView;
    private MapController mapController;
    private LocationManager mLocMgr;
    private ItemizedOverlay<OverlayItem> mMyLocationOverlay;
    private ResourceProxy mResourceProxy;
    int longtitude = 31987968;
    int latitude = 34783155;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
        setContentView(R.layout.main);

        mMapView = (MapView) this.findViewById(R.id.mapview);
        mMapView.setTileSource(TileSourceFactory.MAPNIK);
        mMapView.setBuiltInZoomControls(true);
        mMapView.setMultiTouchControls(true);
        mapController = this.mMapView.getController();
        mapController.setZoom(15);
        GeoPoint point2 = new GeoPoint(longtitude, latitude); // centre map here
        GeoPoint point3 = new GeoPoint(longtitude + 2000, latitude + 2000); // icon
                                                                            // goes
                                                                            // here
        // 31.987968,34.783155

        mapController.setCenter(point2);
        mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
        mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100,
                this);

        ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
        // Put overlay icon a little way from map centre
        items.add(new OverlayItem("Here", "SampleDescription", point3));

        /* 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(SampleWithMinimapItemizedoverlay.this,
                                "Item '" + item.mTitle, Toast.LENGTH_LONG)
                                .show();
                        return true; // We 'handled' this event.
                    }

                    @Override
                    public boolean onItemLongPress(final int index,
                            final OverlayItem item)
                    {
                        Toast.makeText(SampleWithMinimapItemizedoverlay.this,
                                "Item '" + item.mTitle, Toast.LENGTH_LONG)
                                .show();
                        return false;
                    }
                }, mResourceProxy);
        this.mMapView.getOverlays().add(this.mMyLocationOverlay);
        mMapView.invalidate();
    }

    -------//here I tried to do the change !!!!!!!!!---------------
    -- The map location being updated but not the overlayItem.
    public void onLocationChanged(Location location)
    {
        latitude = (int) (location.getLatitude() * 1E6);
        longtitude = (int) (location.getLongitude() * 1E6);
        Toast.makeText(SampleWithMinimapItemizedoverlay.this,
                "Location changed. Lat:" + latitude + " long:" + longtitude ,
                Toast.LENGTH_LONG).show();
        GeoPoint gpt = new GeoPoint(latitude, longtitude);
        mapController.setCenter(gpt);
        mMapView.invalidate();
    }

    @Override
    public void onProviderDisabled(String arg0)
    {
    }

    @Override
    public void onProviderEnabled(String provider)
    {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)
    {
    }

}

Thanks,

ray.

  • 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-05-23T11:31:17+00:00Added an answer on May 23, 2026 at 11:31 am

    This should work OK

    .

    public class SampleWithMinimapItemizedoverlay extends Activity implements
            LocationListener, MapViewConstants {
    
        private MapView mMapView;
        private MapController mapController;
        private LocationManager mLocMgr;
        private ItemizedOverlay<OverlayItem> mMyLocationOverlay;
        private ResourceProxy mResourceProxy;
        int mLongtitude = 31987968;
        int mLatitude = 34783155;
        ArrayList<OverlayItem> mItems;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
            setContentView(R.layout.main);
    
            mMapView = (MapView) this.findViewById(R.id.mapview);
            mMapView.setTileSource(TileSourceFactory.MAPNIK);
            mMapView.setBuiltInZoomControls(true);
            mMapView.setMultiTouchControls(true);
            mapController = this.mMapView.getController();
            mapController.setZoom(15);
            GeoPoint point2 = new GeoPoint(mLongtitude, mLatitude); // centre map here
            GeoPoint point3 = new GeoPoint(mLongtitude + 2000, mLatitude + 2000); // icon
                                                                                // goes
            // 31.987968,34.783155
            mapController.setCenter(point2);
            mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
            mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100,
                    this);
    
            mItems = new ArrayList<OverlayItem>();
            // Put overlay icon a little way from map centre
            mItems.add(new OverlayItem("Here", "SampleDescription", point3));
    
            /* OnTapListener for the Markers, shows a simple Toast. */
            // REFER TO THE GESTURE LISTEMER BY NAME NOW
            this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems,
                    new Glistener() , mResourceProxy);
            this.mMapView.getOverlays().add(this.mMyLocationOverlay);
            mMapView.invalidate();
        }
    
        //We can't use an anonymous class anymore if we want to change the position
        // of the overlays/icons when location changed, give it a name
        class Glistener implements OnItemGestureListener<OverlayItem> {
            @Override
            public boolean onItemLongPress(int index, OverlayItem item) {
                Toast.makeText(SampleWithMinimapItemizedoverlay.this, "Item " + item.mTitle,
                        Toast.LENGTH_LONG).show();
    
                return false;
            }
    
            @Override
            public boolean onItemSingleTapUp(int index, OverlayItem item) {
                Toast.makeText(SampleWithMinimapItemizedoverlay.this, "Item " + item.mTitle,
                        Toast.LENGTH_LONG).show();
                return true; // We 'handled' this event.
    
            }
    
        }
        // -------//here I tried to do the change !!!!!!!!!---------------
        // -- The map location being updated but not the overlayItem.
        public void onLocationChanged(Location location) {
            mLatitude = (int) (location.getLatitude() * 1E6);
            mLongtitude = (int) (location.getLongitude() * 1E6);
            Toast.makeText(SampleWithMinimapItemizedoverlay.this,
                    "Location changed. Lat:" + mLatitude + " long:" + mLongtitude,
                    Toast.LENGTH_LONG).show();
            GeoPoint gpt = new GeoPoint(mLatitude, mLongtitude);
            mapController.setCenter(gpt);
            mItems.clear(); // COMMENT OUT THIS LINE IF YOU WANT A NEW ICON FOR EACH CHANGE OF POSITION
            mItems.add(new OverlayItem("New", "SampleDescription", gpt));
            // Change the overlay
            this.mMyLocationOverlay = new ItemizedIconOverlay<OverlayItem>(mItems,
                    new Glistener() , mResourceProxy);
            this.mMapView.getOverlays().clear();
            this.mMapView.getOverlays().add(this.mMyLocationOverlay);
            mMapView.invalidate();
        }
    
        @Override
        public void onProviderDisabled(String arg0) {
        }
    
        @Override
        public void onProviderEnabled(String provider) {
        }
    
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    
    }
    

    Just comment/uncomment the mItems.clear(); line depending on whether you want a new marker each time you change position. (The icon appears atthe position that you have moved to)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to display the current position pointer using osmdroid. getController().setCenter(new GeoPoint(location)); This
I m using Osmdroid to create an offline map Now, i want to implement
Using restlet, I want to make a post to android's c2dm service. I have
I'd previously managed to incorporate OpenStreetMaps into my application using osmdroid-android-3.0.1.jar with the great
I am currently using osmdroid jar 3.0.1, and I have a MapView inside a
I have been working on an offline map using OSMdroid I have map tiles
I have an Android application that showing maps using OSMDroid. I want to get
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using android 2.3.3, I have a background Service which has a socket connection. There's

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.