Fetch offline location using FusedLocationApi - android

I want to fetch the location using google play services LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); when GPS/Wifi is turned off. Reading the articles/blogs regarding FusedLocationApi, its mentioned that this API will provide the accurate location using any of GPS/Wifi or Cellular network. I am confused that if cellar network can provide the location then FusedLocationApi should return the location if Gps/Wifi is disabled but its returning null. Can anyone please let me help/guide to fetch offline location using cellular network.
Regards

You cannot get location using the cellular network through the standard API when GPS and WiFi location are disabled.
The device must have location enabled in order for an application to retrieve location. This is a basic permissions issue for the end user; if the end user requests that no location be available, then no location is available.
When retrieving location, there are two sources of information:
GPS: This uses satellites in space to locate the device. GPS provides the most accurate location, but is slow, especially if you do not have a data connection. On the device this is the "device only" mode.
Network: This uses WiFi and/or the cellular network. There is not a way to choose WiFi and cellular location separately. When you get a location update, the horizontal accuracy is a strong indicator of whether WiFi or the cellular network was used. WiFi accuracy should be in 10's of meters, while cellular will probably be 100's of meters. If you are in an area without WiFi coverage but with cellular coverage, then the network source will still provide location updates.
You can also use both these sources. This is the "high accuracy" location mode.
If you turn both of these off (disable location), then you will not get any location.

Related

Can GPS location be acquired in a phone without internet and SIM?

I'm trying to develop an android application which can acquire GPS location without using Internet and even network location using SIM. Actually, SIM will be inserted in phone and i know that location upto 500m accurate can be acquired through it. But in case of no SIM signals in the area, is it possible to acquire location?
Yes, you can use GPS without any external data connection because signals from the GPS satellites are receive-only.
On a device, the permission setting is known as device-only location mode:
Device only
This mode uses only GPS. It doesn’t use Google's Location service to provide location information. It can estimate your device's location slower and use more battery.
Yes You can get the coordinates but for using map services you need internet.The only thing is your GPS will take a bit longer to lock your location on a cold start, and it might not be quite as accurate.
It's a aGPS (Assisted GPS), and get's part of the location information from the data network (If available) on cold start, then fine-tunes the location further than what a GPS alone can do.
Shouldn't be an issue however, really. Just turn your GPS on a little sooner (Like while getting ready to leave, not waiting until you are in your car).
Yes. If you use the Location Manager, set the Provider to LocationManager.GPS_PROVIDER. If you use Google Play Services, it should work automatically.

How do I use the device's GPS only whenever there is no internet available?

Android is constantly changing. Currently, the Fused Location API is being used for location detection. But in my experience, without a Data connection, the GPS signal is not being found anymore.
How do I use the device's GPS only whenever there is no internet available?
Fused location provider uses a hybrid way to find gps using a variety of sensors, WIFI/data and the actual GPS chipset.
It will find the location COARSE/FINE accuracy is up to your case. It will just take a while longer than with the internet connection. If indoors or in an isolated area, it may very well take over a minute or two. Sometimes if the data signals just don't reach the device, yes it can fail.
It does work without WIFI or DATA in most cases.

Getting the status of the GPS

The answer to the question here provides the method to activate the location if it has been turned off.
Now, Android has three location settings currently:
High Accuracy: Uses GPS, WiFi and cellular network to get the location.
Battery Saving: Uses cellular networks and WiFi to determine the location.
Device only: Uses GPS to determine the users location.
Checking the location status using the line:
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
I redirect the user to the Activity where he can switch on the location. Now if the user turns on the location in the battery saving mode, will I get the location.
Also, for the redirection I do:
context.startActivity(myIntent)
Is there anyway to call startActivityForResult() here to verify if the user has turned on the location and depending on that redirect the user to different activities?
In Battery Saving mode GPS is OFF, so through GPS you will not get the location. but in Battery saving mode you can use WIFI and Mobile networks to determine the location

FusedLocationProvider finds location faster with GPS turned of

My android app relies on location. However the FusedLocationProvider which I use for this as abstraction layer so that I do not have to worry about what LocationProvider to use, behaves unexpectedly.
Scenario:
User opens app. I check for the availability of the providers and open the location settings page. The user enables "Access to my location" and both GPS and Wi-Fi location. When the user returns to the app I receive no location updates.
When I leave GPS turned off and only allow Wi-Fi in the System settings, I get an updated location.
I tried the priorities PRIORITY_LOW_POWER and PRIORITY_BALANCED_POWER_ACCURACY which both did not give me a location update when GPS was turned off.
How does it come, that the detection of the location works with GPS turned off and doesn't when it is turned on? Does that make any sense?
The location I obtain, when GPS is turned off is accurate enough for what the app is doing. If the device has had LocationServices turned on for a longer periods of time (Including the phone being outside) I receive Location Updates even with GPS turned on.
Does someone have an explanation for this / know how to solve this?

get current location without internet - phonegap geolocation api for android

I am trying to get the user's current location using phonegap Geolocation api, which says "Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs". I am able to properly get the location when internet is ON (irrespective of the state of GPS).
Is there a way to get the location using triangulation when the internet is OFF or not accessible? (GPS might be ON or OFF)
A BIG "NO"! This is like cutting down hands and asking if I could clap now? GPS and NETWORK location providers are the only way to receive user device location.
For GPS location - you need GPS sensors to be ON.
And for NETWORK location you need to have internet connection ON, because in this case the location is calculated on the basis of Cell-Tower/Wifi-spot ID which is then sent to google servers (via internet) to fetch the location details of the respective Cell Tower or wifi spot. Google's location server have its own location approximation algorithms on the basis of which it tells your location.
So, there could be no way you could receive a location when both GPS and INTERNET are OFF.
Note: You can still get the last received location from any of these providers by using LocationManager's getLastKnownLocation() even when the providers are OFF. But this locations are usually outdated ones and are barely of any use.
{ enableHighAccuracy: true }
Enabling that option will allow the Android device to get the location even with the WIFI option disabled.

Categories

Resources