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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:36:05+00:00 2026-05-17T02:36:05+00:00

I am having a problem in getting GPS coordinates in 2.1. The code i

  • 0

I am having a problem in getting GPS coordinates in 2.1.

The code i am using right now is working well in 1.6 but when i test
this same apk in 1.6 device is showing null values

please help me to find a way to work with 2.1 devices also

Here is my code.

public class GpsLocator {

   private static String PROVIDER="gps";
   private LocationManager myLocationManager=null;

   public GpsLocator(Context context) {
      myLocationManager=(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
   }

   public void myOnresume() {
      myLocationManager.requestLocationUpdates(PROVIDER, 0,   0, onLocationChange);
   }

   public void myonPause() {
       myLocationManager.removeUpdates(onLocationChange);
   }

   public double getLatitude() {
      Location loc=myLocationManager.getLastKnownLocation(PROVIDER);
      if (loc==null) {
         return(0);
      }
      return(loc.getLatitude());
   }

   public double getLongitude() {
      Location loc=myLocationManager.getLastKnownLocation(PROVIDER);
      if (loc==null) {
         return(0);
      }

      return(loc.getLongitude());
   }

   LocationListener onLocationChange=new LocationListener() {

      public void onLocationChanged(Location location) {
      }

      public void onProviderDisabled(String provider) {
         // required for interface, not used
      }

      public void onProviderEnabled(String provider) {
         // required for interface, not used
      }

      public void onStatusChanged(String provider, int status,Bundle extras) {
         // required for interface, not used
      }
   };
}

in the manifest file i add permission for accessing file they are

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  • 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-17T02:36:05+00:00Added an answer on May 17, 2026 at 2:36 am
        LocationManager locationManager;
        String context = Context.LOCATION_SERVICE;
        locationManager = (LocationManager)getSystemService(context);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = locationManager.getBestProvider(criteria, true);
    
        Location location = locationManager.getLastKnownLocation(provider);
    
        updateWithNewLocation(location);
    
        locationManager.requestLocationUpdates(provider, 2000, 10,   
                                               locationListener);
      }
    
      private final LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
          updateWithNewLocation(location);
        }
    
        public void onProviderDisabled(String provider){
          updateWithNewLocation(null);
        }
    
        public void onProviderEnabled(String provider){ }
        public void onStatusChanged(String provider, int status, 
                                    Bundle extras){ }
      };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problem getting this piece of code to run. The class is
I'm having a problem getting this test case to work. Can anyone point me
I'm having a problem getting this type conversion working correctly. My guess is the
Having a problem getting the URL for a resource for some reason: This code
I am having a problem getting my shellscript working using backticks. Here is an
I'm having a problem getting a pseudo class working with my code. The code
I am having problem getting my tooltip to work when using the jQuery load()
I'm having a problem getting a change event to register with the following code:
I am having problem in getting reference of Ajax control extender using $find() or
I am having a problem getting onprogress event for the audio tag working on

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.