Check if provided location info from fused location provider is from GPS - android

We are using fused location provider and if I query location.getProvider() on the location I'm receiving it returns fused. I would like to check whether the fused provider used GPS or Wifi or both for the location it gave me. is this possible? how?

The fused provider does not provide you with the specific location provider it only returns fused as you said, if you want to listen for a specific provider you need to use the old LocationManager

Related

Android Fused Location Api

I am using Fused Location Api for getting the latitude and longitude.It's mentioned in the documents that it uses GPS,Wifi and network to return the most accurate location of the user.I want to ask is that will it return the position if the GPS in my phone is switched off?
Fused Location Provider will automatically choose the best location from the options available. It will select from GPS or Network location Provider. So if the device GPS is not on, you should still be able to get a location based on the network location provider, if that is enabled on the device.
You will need to have permissions for ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION to receive both kinds of locations.

How do I know the provider pf LocationManager's GPS retrieval?

I am trying to log information about how the app is fetching the coordinates. This is the code I used to grab the coordinates.
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
location = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);
My question is, how do I find out the source of the coordinates? (GPS, Network Triangulation, Wifi, etc. )
In other words, getLastKnownLocation returns coordinates from multiple sources, how do I get a string name of the source?
You use NETWORK_PROVIDER. This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup.
GPS_PROVIDER determines location using satellites.

do I need to enable gps when using NETWORK_PROVIDER

I've written an android application that needs the user location, it was working fine when I used gps provider, but I don't want to use GPS because it uses a lot of battery, here is my code
LocationManager locaionManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,5*1000,0, new MyLocaionListener());
Location loco = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.d("enabled=" ,"" + locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
This code returns a null Location Object, and the logCat shows enabled=false when the location service is disabled although I'm using NETWORK_PROVIDER But when I enable the location service from the phone settings I get enabled=true and I get my current location.
So my question is:
does network provider also uses the phone GPS? and how do GPS and NETWORK providers internally works.

in android, GPS_PROVIDER works, but NETWORK_PROVIDER does not

I am building an android application.
I can get GPS coordinates fine using
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
But when I try to use the network provider (editing the line, not doing two registers)
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,0,locationListener);
I get no coordinates.
I am checking if I have coordinates doing a println(location.toString()) inside the locationListener.
Both GPS and WIFI location are enabled on the device (and, as far as I can tell, other applications manage to use WIFI location)
Am I missing something? Is there a special procedure to use NETWORK_PROVIDER ?
(I have only "fine location" permissions, but the docs explicitly say this also allows "coarse location")
gps –> (GPS, AGPS): Name of the GPS location provider. This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION.
network –> (AGPS, CellID, WiFi MACID): Name of the network location provider. This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup. Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.

Find location source using Fused Location Provider

AFAIK, fused location provider can use network or gps data depending on different conditions. Is it possible to find which exact location data source (WiFi, Cellular, GPS) was used after getting location with fused location provider? All I want is to show some notification on screen about the source of location data, like it's done in 2Gis app.
No,
Fused location provider:
The Fused Location Provider intelligently manages the underlying location technology and gives you the best location according to your needs.
It may use combo of that data.

Categories

Resources