Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPS_PROVIDER Error in Android Application

I have created an Android app to retrieve the location. I tried to use GPS_PROVIDER, it returned null.. But works smooth when i use NETWORK_PROVIDER.. Can any one help me fixing this?

Here is the code

Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

The location turns null when i replace "NETWORK_PROVIDER" by "GPS_PROVIDER"..

I have added the following three permissions in manifest

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
like image 529
humandroid Avatar asked Mar 11 '26 05:03

humandroid


1 Answers

There can be two reasons why your GPS location is null

  1. May be your GPS is not active. Try to active your GPS from the setting menu => Location & Security => Check Use GPS Satellites.
  2. May be you are currently in the building where the GPS is not working. Check it by coming out from the building. This can be happen most of time.
like image 100
Dharmendra Avatar answered Mar 12 '26 17:03

Dharmendra