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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:11:57+00:00 2026-06-09T14:11:57+00:00

I need to show my current location as the Marker always on the Google

  • 0

I need to show my current location as the Marker always on the Google Map using ItemizedOverlay but whenever I run the below code, my marker doesn’t showed up if I change the location from DDMS. Below is my code. Is there anything wrong I am doing?

public class MainActivity extends MapActivity {
    private MyItemizedOverlay myItemizedOverlay = null;
    private LocationManager locationManager = null;
    private MapView mapView = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

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

        //GeoPoint myPoint1 = new GeoPoint((int) (37.347184*1000000), (int) (-121.966551*1000000));
        myItemizedOverlay.addItem(point, "myPoint1", "myPoint1");
        mapController.animateTo(point);
        String address = ConvertPointToLocation(point);
        Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

        mapView.invalidate();

    }


}

Below is MyItemizedOverlay 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();
    }

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

}

As I need to show other Marker’s also on the Google Maps, so that is the reason I was going with ItemizedOverlay concept. Firstly I need to focus on my current location always using ItemizedOverlay whenever my app starts. Any suggestions on my example will be appreciated.

  • 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-09T14:11:58+00:00Added an answer on June 9, 2026 at 2:11 pm

    If all you want to do is display the user’s current location, then use MyLocationOverlay. It is specifically designed for this. Here is a good example on how to use it, and below is the basic central code snippet:

    // This goes into the onCreate method
    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);
    
    myLocationOverlay.runOnFirstFix(new Runnable() {
      public void run() {
        mapView.getController().animateTo(myLocationOverlay.getMyLocation());
         }
    }); 
    

    See the tutorial for a more detailed example.

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

Sidebar

Related Questions

In my android app I need to show the user's current location in Google
I am using MKMapView on my application. i need to show current location on
How do I display users current location in my app, using google maps? I
I am currently showing marker on my current location whenever the current location gets
I need show a notication modal window.. But since its a fluid layout the
I need to show a form using a button, and hide it when the
I'm trying to update a marker in real time on a Google Map. I
I'm developing an android app, I've requirement to show the user current location and
How to decide the current point reach on google map? I have a list
Is there a way to have the MapView not show my current location? I'm

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.