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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:28:44+00:00 2026-06-08T19:28:44+00:00

Location returns always null from this code. Please check my codes and tell me

  • 0

Location returns always null from this code. Please check my codes and tell me whats wrong. When I run the project on debug mode, provider=”network” but location always null. I send latitude and longitude values by using DDMS but doesn’t change. I don’t understand whats is the problem

This part in the onCreate method

lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);

        provider = lm.getBestProvider(criteria, true);
        location = lm.getLastKnownLocation(provider);

            updateLocation(location);

This part in the onResume method

@Override   
    protected void onResume() {  
        super.onResume();
        lm.requestLocationUpdates(provider, 5000, 10, this);
    }

I use LocationListener (MapActivity implements LocationListener) and this is onLocationChanged part

public void onLocationChanged(Location location) {
        updateLocation(location);   
    }

finally this is my updateLocation()

private void updateLocation(Location location){
        if (location != null) {
            Double lat = location.getLatitude()*1E6;
            Double lng = location.getLongitude()*1E6;
            point = new GeoPoint(lat.intValue(), lng.intValue());

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

            //List<Overlay> overlays = mapView.getOverlays();
            myLocOverlay = new MyLocationOverlay(this, mapView);
            //overlays.add(myLocOverlay);
            mapView.getOverlays().add(myLocOverlay);
            myLocOverlay.enableMyLocation();

            myLocOverlay.runOnFirstFix(new Runnable() {
                public void run() {
                    mc.animateTo(myLocOverlay.getMyLocation());
                    }
            }); 

            mc.setZoom(15);
            mapView.invalidate();

            }

    }

I gave essential permissions and I use google maps library

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

<uses-library
            android:name="com.google.android.maps"
            android:required="true" >
        </uses-library>
  • 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-08T19:28:45+00:00Added an answer on June 8, 2026 at 7:28 pm

    I think u should use LocationManager.GPS_PROVIDER to request. You can test my code:

    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1l,1f, new LocationListener() {        
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
             // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
            updateLocation(location);               
        }
        });
    

    Good luck!
    ^-^

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

Sidebar

Related Questions

Given the code below, ReadProcessMemory always returns an array of zeros. I'm trying to
I am trying to get an Current Altitude from location.getAltitude() method. but it always
I'm running an MySQL query that returns results based on location. However I have
I wrote this HttpRequest method, but for some reason it always goes to 404
I am having difficulty getting my Monodroid application retrieve a location when I run
I can't read location with this function. When I try to get location information,
I am using the following code to get my current location. But the problem
I am new to geocode. I am getting the zip code from the user
According to Android documentation, using the .getTime() method in the Android location will return
So I need to return the location or fname or what ever.... I would

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.