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

  • Home
  • SEARCH
  • 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 6322269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:17:59+00:00 2026-05-24T16:17:59+00:00

I am developing an Android app which uses the current user location for result.

  • 0

I am developing an Android app which uses the current user location for result.

I am using the following code to get the location:

LocationManager locationManager =
    (LocationManager) getSystemService(LOCATION_SERVICE);

Location currentLocation =
    locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

When I run it on device it gives me a null value for location.

But when I use the NETWORK_PROVIDER it works fine is there any extra setting for the device to use GPS?

My device is Galaxy Tab P-1000.

  • 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-05-24T16:18:00+00:00Added an answer on May 24, 2026 at 4:18 pm

    Use:

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                    MINIMUM_TIME_BETWEEN_UPDATES,
                    MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
    

    For locationListener you may use this:

    LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                // Called when a new location is found by the network location
                // provider.
    
                String message = String.format(
                        "New Location \n Longitude: %1$s \n Latitude: %2$s",
                        location.getLongitude(), location.getLatitude());
                Toast.makeText(LbsGeocodingActivity.this, message,
                        Toast.LENGTH_LONG).show();
    
                if (location != null) {
                    GeoPoint point2 = new GeoPoint(
                            (int) (location.getLatitude() * 1E6), (int) (location
                                    .getLongitude() * 1E6));
    
                    // Toast.makeText(getBaseContext(),
                    // "Latitude: " + location.getLatitude() +
                    // " Longitude: " + location.getLongitude(),
                    // Toast.LENGTH_SHORT).show();
                    //                 
                    mapView.getController().animateTo(point2);
                    mapView.getController().setZoom(15);
    
                    List<Overlay> mapOverlays = mapView.getOverlays();
                    Drawable drawable = LbsGeocodingActivity.this.getResources()
                    .getDrawable(R.drawable.new3pin);
                    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
                            drawable, LbsGeocodingActivity.this);
                    point = new GeoPoint((int) (location.getLatitude() * 1E6),
                            (int) (location.getLongitude() * 1E6));
    
                    String address = convertPointToLocation(point);
                    String delims = ",";
                    String[] tokens = address.split(delims);
                    OverlayItem overlayitem = null;
                    if(tokens.length==1)
                    {
    
                        overlayitem = new OverlayItem(point,
                                "New Location", "Locality:"+"\nCity:"+"\nCountry: "+tokens[0]);
                    }
                    else if(tokens.length==2)
                    {
    
                        overlayitem = new OverlayItem(point,
                                "New Location", "Locality:"+"\nCity: "+tokens[0]+"\nCountry: "+tokens[1]);
                    }
                    else if(tokens.length==3)
                    {
    
                        overlayitem = new OverlayItem(point,
                                "New Location", "Locality: "+tokens[0]+"\nCity: "+tokens[1]+"\nCountry: "+tokens[2]);
                    }
                    else
                    {
                        overlayitem = new OverlayItem(point,
                                "New Location", address);
                    }
    
                    itemizedoverlay.addOverlay(overlayitem);
                    mapOverlays.clear();
                    mapOverlays.add(itemizedoverlay);
    
                    // mapView.invalidate();
                }
    
            }
    

    I have used this in my code and it works well.

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

Sidebar

Related Questions

I am developing an Android app which needs to poll a specific webpage in
I am developing an app in android, which basically visits a given url and
Has anybody had any success with developing for Android platform using Netbeans (5.5+ )
I'm kinda noob to android so please bear with me. I'm currently developing app
I have been developing an Android app and testing with a 1.5 AVD and
I am developing an application which uses Bluetooth to connect to a device and
I'm developing on Android and currently haev various methods which manage my database in
I'm developing an Android app (Android 1.6), but this is probably a more general
I'm developing an android app (if you want more info http://www.txty.mobi ) and I
I am developing an app for android mobiles that communicates with a json/rest web

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.