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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:43:27+00:00 2026-06-09T15:43:27+00:00

I am currently showing marker on my current location whenever the current location gets

  • 0

I am currently showing marker on my current location whenever the current location gets changed. And the below code works fine. But the problem with this is,- Suppose for the first time I passed some location and my marker will be there at that position but the second time if I pass any other different location then my marker will be there in second location but at the same time my marker also stays in First Location too and I don’t want this thing. I only need whenever the Current Location changes all other marker should gets disappeared, only the current location marker should be there. Hope I am clear to everyone

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);
        mapController = mapView.getController();
        mapController.setZoom(15);

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, new GeoUpdateHandler());

    }

    public class GeoUpdateHandler implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
            int lat = (int) (location.getLatitude() * 1E6);
            int lng = (int) (location.getLongitude() * 1E6);

            Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
            int markerWidth = marker.getIntrinsicWidth();
            int markerHeight = marker.getIntrinsicHeight();
            marker.setBounds(0, markerHeight, markerWidth, 0);


            myItemizedOverlay = new MyItemizedOverlay(marker);
            mapView.getOverlays().add(myItemizedOverlay);


            GeoPoint point = new GeoPoint(lat, lng);

            myItemizedOverlay.addItem(point, "myPoint1", "myPoint1");
            mapController.animateTo(point);
            String address = ConvertPointToLocation(point);
            Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

            mapView.invalidate();

        }
}

Below is my ItemizedOverlay class-

public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem>{

    private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();

    public MyItemizedOverlay(Drawable marker) {
        super(boundCenterBottom(marker));
        // TODO Auto-generated constructor stub

        populate();
    }

    public void addItem(GeoPoint p, String title, String snippet){
        OverlayItem newItem = new OverlayItem(p, title, snippet);
        overlayItemList.add(newItem);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return overlayItemList.get(i);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return overlayItemList.size();
    }

    public void clear() {
        overlayItemList.clear();
        populate();
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        // TODO Auto-generated method stub
        super.draw(canvas, mapView, shadow);
        //boundCenterBottom(marker);
    }

}
  • 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-09T15:43:29+00:00Added an answer on June 9, 2026 at 3:43 pm

    you just have to remove previously added items before adding the new one

    public void addItem(GeoPoint p, String title, String snippet){
        OverlayItem newItem = new OverlayItem(p, title, snippet);
        overlayItemList.removeAll();
        overlayItemList.add(newItem);
        populate();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code for showing the marker in the current location...but
I am showing current location using a red marker and some other set of
I want to add a parameter to a URL but currently it isnt showing
I currently have the following code which delays showing a fixed bar after a
Hear is my project In my project I am showing my current location,showing the
Hi I have this weird problem with Google Maps V3 API. Showing multiple markers
This is my below code which is drawing a Circle within Circle and taking
Problem Statement:- In my below code, I am getting list of User's which I
Currently have the infowindow showing as the 'what happens' when the map marker is
So I am currently showing a notification. When the user clicks this noticiation, 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.