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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:34:51+00:00 2026-06-15T15:34:51+00:00

I can enable a myLocation View in the new Maps Api through setMyLocationEnabled .

  • 0

I can enable a myLocation View in the new Maps Api through setMyLocationEnabled.

The first version of the Api had a Method runOnFirstFix that enabled me to animate the map to the users location once the location is found. I can not find a listener or location like that in the Api Version 2.

Is there a solution to execute an action once the user is located?

  • 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-15T15:34:52+00:00Added an answer on June 15, 2026 at 3:34 pm

    Google Maps Android API V2 has a LocationSource. From the docs:

    “A GoogleMap object has a built-in location provider for its my-location layer, but it can be replaced with another one that implements this interface.”

    LocationSource

    I imagine you’ll need to use that in conjunction with a LocationSource.OnLocationChangedListener

    Update

    Figured it out. If you want to do something similar to runOnFirstFix, here’s a basic example that waits until the User’s location is available, then animates the map to center on their location.

    public class MyLocationMapFragmentActivity extends FragmentActivity implements LocationListener, LocationSource
    {
    /**
     * Note that this may be null if the Google Play services APK is not available.
     */
    private GoogleMap mMap;
    
    private OnLocationChangedListener mListener;
    private LocationManager locationManager;
    
    private Context mContext;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.basic_map);
    
        this.mContext = this;
    
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    
        //You may want to pass a different provider in as the first arg here
        //depending on the location accuracy that you desire
        //see LocationManager.getBestProvider()
        Criteria locationCriteria = new Criteria();
        locationCriteria.setAccuracy(Criteria.ACCURACY_FINE);
        locationManager.requestLocationUpdates(locationManager.getBestProvider(locationCriteria, true), 1L, 2F, this);
    
        setUpMapIfNeeded();
    }
    
    @Override
    public void onPause()
    {
        if(locationManager != null)
        {
            locationManager.removeUpdates(this);
        }
    
        super.onPause();
    }
    
    @Override
    public void onResume()
    {
        super.onResume();
    
        setUpMapIfNeeded();
    
        if(locationManager != null)
        {
            mMap.setMyLocationEnabled(true);
        }
    }
    
    
    /**
     * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
     * installed) and the map has not already been instantiated.. This will ensure that we only ever
     * call {@link #setUpMap()} once when {@link #mMap} is not null.
     * <p>
     * If it isn't installed {@link SupportMapFragment} (and
     * {@link com.google.android.gms.maps.MapView
     * MapView}) will show a prompt for the user to install/update the Google Play services APK on
     * their device.
     * <p>
     * A user can return to this Activity after following the prompt and correctly
     * installing/updating/enabling the Google Play services. Since the Activity may not have been
     * completely destroyed during this process (it is likely that it would only be stopped or
     * paused), {@link #onCreate(Bundle)} may not be called again so we should call this method in
     * {@link #onResume()} to guarantee that it will be called.
     */
    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) 
        {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.basicMap)).getMap();
            // Check if we were successful in obtaining the map.
    
            //This is how you register the LocationSource
            mMap.setLocationSource(this);
    
            if (mMap != null) 
            {
                setUpMap();
            }
        }
    }
    
    /**
     * This is where we can add markers or lines, add listeners or move the camera. In this case, we
     * just add a marker near Africa.
     * <p>
     * This should only be called once and when we are sure that {@link #mMap} is not null.
     */
    private void setUpMap() 
    {
        mMap.setMyLocationEnabled(true);
    }
    
    @Override
    public void activate(OnLocationChangedListener listener) 
    {
        mListener = listener;
    }
    
    @Override
    public void deactivate() 
    {
        mListener = null;
    }
    
    @Override
    public void onLocationChanged(Location location) 
    {
        if( mListener != null )
        {
            mListener.onLocationChanged( location );
    
            //Move the camera to the user's location once it's available!
            mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
        }
    }
    
    @Override
    public void onProviderDisabled(String provider) 
    {
        // TODO Auto-generated method stub
        Toast.makeText(this, "provider disabled", Toast.LENGTH_SHORT).show();
    }
    
    @Override
    public void onProviderEnabled(String provider) 
    {
        // TODO Auto-generated method stub
        Toast.makeText(this, "provider enabled", Toast.LENGTH_SHORT).show();
    }
    
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) 
    {
        // TODO Auto-generated method stub
        Toast.makeText(this, "status changed", Toast.LENGTH_SHORT).show();
    }
    }
    

    Update 2

    If you’re interested in centering the map on the user’s location when their location goes off screen (like MyLocationOverlay does in the old API), see this answer

    or this blog post: Google Maps Android API V2 MyLocation LocationSource and event handling

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

Sidebar

Related Questions

I see that you can enable/disable using the EnableWindow method, but how do I
I know that rsync can enable / disable the ssh encryption protocol during the
MinGW has this option you can enable that shows warnings suggested by Scott Meyers'
I'm trying to use the new google maps android api v2 and i'm developing
Is there any tool out there that can enable me to clearly see where
I got answer from the SDL Tridion forum that we can enable inline editing
I want to launch mobile network settings screen, so that user can enable/disable 3g
how can I disable and enable the mobile data(3G) on Android? I read that
Is there a way to construct another element that can enable posting of files
Does anyone know how I can enable a two-column view of the e-mail in

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.