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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:13:49+00:00 2026-06-17T13:13:49+00:00

I am now moving with a project related to Google Map service. I would

  • 0

I am now moving with a project related to Google Map service. I would like to point out my current location in my map. For that, I have got an idea of using itemizedoverlay. I retrieve the current location by the help of Geopoint. But when I’m used the itemizedoverlay in my code, the location cannot be picked up and I am using this in my OnCreate method. If I am moving this to OnLocationChanged method, then GeoPoint(point) will not be picked up by the itemizedoverlay and will end with an error and in the present condition, the app gets crushed down.

        MapView mapView;
    Location location;
    LocationManager locationmanager;
    LocationListener locationlistener; 

        public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

      mapView = (MapView) findViewById(R.id.mapView);
      mapView.setTraffic(true);
      mapView.setBuiltInZoomControls(true);

        //locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);  
   // locationlistener = new GPSLocationListener();
      //  locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER 0,0,locationlistener);                                                                                         

      GeoPoint point = new GeoPoint(
                (int) (location.getLatitude() * 1E6), 
                (int) (location.getLongitude() * 1E6));

            Toast.makeText(getBaseContext(), 
                "Latitude: " + location.getLatitude() + 
                " Longitude: " + location.getLongitude(), 
                Toast.LENGTH_SHORT).show();

      List<Overlay> mapOverlays = mapView.getOverlays();
      Drawable drawable = this.getResources().getDrawable(R.drawable.icon);


          HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
          OverlayItem overlayitem = new OverlayItem(point,"","" );
          itemizedoverlay.addOverlay(overlayitem);
          mapOverlays.add(itemizedoverlay);

}

/*      private class GPSLocationListener implements LocationListener 
      {
        @Override
        public void onLocationChanged(Location location) {
          if (location != null) {
            GeoPoint point = new GeoPoint(
                (int) (location.getLatitude() * 1E6), 
                (int) (location.getLongitude() * 1E6));

            Toast.makeText(getBaseContext(), 
                "Latitude: " + location.getLatitude() + 
                " Longitude: " + location.getLongitude(), 
                Toast.LENGTH_SHORT).show();

            OverlayItem overlayitem = new OverlayItem(point,"","" );
              itemizedoverlay.addOverlay(overlayitem);
              mapOverlays.add(itemizedoverlay);

}
        } */


    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderDisabled(String provider) {

Toast.makeText(getBaseContext(),"GPS Disabled",Toast.LENGTH_SHORT).show();      

    }

    @Override
    public void onProviderEnabled(String provider) {

        Toast.makeText(getBaseContext(),"GPS Enabled",Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

Can you please suggest me a solution for this?? Thanks In Advance and sorry if I made any mistakes here.

  • 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-17T13:13:51+00:00Added an answer on June 17, 2026 at 1:13 pm

    You can use com.google.android.maps.MyLocationOverlay which will automatically get show your location on your map view. It will even update your location when travelling.

    Note: you show call enableMyLocation and disableMyLocation on onResume and onPause respectively for better performance.

    @Override
        protected void onResume() {
            super.onResume();
            if (locationOverlay != null)
                locationOverlay.enableMyLocation();
        }
    
        @Override
        protected void onPause() {
            if (locationOverlay != null)
                locationOverlay.disableMyLocation();
            super.onPause();
        }
    

    EDITED

    MyLocationOverlay locationOverlay;
    
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
    
          mapView = (MapView) findViewById(R.id.mapView);
          mapView.setTraffic(true);
          mapView.setBuiltInZoomControls(true);
    locationOverlay = new MyLocationOverlay(this, mapView);
    List<Overlay> mapOverlays = mapView.getOverlays();
     mapOverlays.add(locationOverlay);
    }
    

    also add the onResume() and onPause() methods.

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

Sidebar

Related Questions

I have a project that used to be under SVN, but now I'm moving
for a project in OpenCV I would like to segment moving objects as good
I have a git clone/repo on a development server, but I am now moving
We have been using gforge server for cvs/svn. Now we are moving to git.
We're moving away from TFS as a source control/build service. We're now using TeamCity,
now i'm working on a project for creating audio unit instrument that provide the
Now I try to developing an application related to Image processing, for that I
I have an existing (C# based) windows service that is derived from the Installer
I have an existing WCF RIA project built on the Release Candidate; I'm now
We have a fairly large C++ project which I am now in the process

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.