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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:47:40+00:00 2026-06-17T17:47:40+00:00

I need to get the Users Location for my app so that i can

  • 0

I need to get the Users Location for my app so that i can display the directions on Google Maps based on two Lat and Long.

If the Users GPS is switched off it should ask the user if he wants to switch on the GPS and should be able to take him the Settings to switching it on.

i am trying the following but it takes me directly to the settings i wonder how to let the user ask if he wants to be taken away.

Is there any Library that does this efficiently i would prefer using it to get the Lat and Long of the user.

  • 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-17T17:47:42+00:00Added an answer on June 17, 2026 at 5:47 pm

    You will need to do several things.

    Firstly, to incorporate Google Maps, your complete reference is available here.

    In simple steps:

    1 Follow the steps here: this will help add a simple google maps to your screen.

    2 To be able to get your own location you will need to use the LocationListener and LocationManager in android. To do this, first implement the LocationListener in your activity.

    public class LocationActivity extends Activity implements LocationListener

    3 Then you need to instantiate a few settings in your onCreate() method

         @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            // Get the location manager
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        // Define the criteria how to select the provider
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        provider = locationManager.getBestProvider(criteria, false);
        Location location = locationManager.getLastKnownLocation(provider);
    
        // Initialize the location fields
        if (location != null) {
          System.out.println("Provider " + provider + " has been selected.");
          onLocationChanged(location);
        } 
      }
    

    4 You need to be able to request for regular location updates. Include this in your onResume() method.

    @Override
      protected void onResume() {
        super.onResume();
        locationManager.requestLocationUpdates(provider, 400, 1, this);
      }
    

    5 If the app falls into the pause cycle, these updates shouldn’t need to come.

    @Override
      protected void onPause() {
        super.onPause();
        locationManager.removeUpdates(this);
      }
    

    6 Your location listener implementation from step 2 requires that you have an onLocationChanged listener, implement it:

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

    7 Add these two methods to be notified of the provider of your location setting – the GPS or the Network.

    public void onProviderDisabled(String arg0) {
        Toast.makeText(this, "Disabled provider " + provider,
                    Toast.LENGTH_SHORT).show();
    }
    
    public void onProviderEnabled(String arg0) {
        Toast.makeText(this, "Enabled new provider " + provider,
                    Toast.LENGTH_SHORT).show();
    }
    

    8 Now we need to link this up to your google maps. I will show you one example of using the google maps API to be able to generate a market to show your current location. The other usages can be inferred from the API.

    First create private fields in your code:

    private GoogleMap mMap;
    Marker m;
    

    9 Add these in your onCreate method – this instantiates your default marker position as 0,0 latitude and longitude.

    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                    .getMap();
    m = mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0))
                    .title("Position"));
    

    10 In your onLocationChanged method, we need to refresh this marker as location changes. So add:

    m.setPosition(new LatLng(lat, lng));
    m.setTitle("Your Position");
    
    // Move the camera instantly to marker with a zoom
    // of 15.
                                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 15));
    

    This will be a simple way of updating the marker with your position, and should be a good intro to your Google Maps and location API in android.

    To detect if GPS is on or not you can use the answer provided by @Dror 🙂 Hope it helps!

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

Sidebar

Related Questions

I need to verify that users of my app are within the US. Currently
I am writing a location based App and want to get some wisdom on
i want to build an app for windows mobile that can get GPS locations(longitude
I need to get the users Loging name from NTLM . Any one who
i have a problem with sql query. I need to get list of users.
Hi i'm making an app which need to get user's gmail account contact list
Is there any way that a webpage can make a request for the users
I am working on an app that uses location. When starting the app, it
Ive got an app that plots mkannotations (i hope i get my terminology right...its
I'm thinking about creating a location-aware iPhone app that could work offline by coming

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.