get coordinates without gps (android) - android

I'm developing a android app and I want to receive coordinates from a smartphone. Two questions:
1: GPS is enabled, but there is no signal, so I have no coordinates. How can I check, if GPS is sending coordinates or not?
2: If GPS is enabled and there is no signal, which other method can I use to get the coordinates from the smartphone?

Getting coordinates requires using the location services, which by default uses all manner to determine location, not just the GPS, but cellular signals as well. Here is a tutorial on using the location services in Android.
One word of advice - if you are going to use GPS and generally distribute your app, know that the GPS service is VERY battery intensive. It requires judicious coding to not drain your users battery. You have been warned!

1) fetch device coordinates using locationService.
mContext = getActivity();
mLocationManager = (LocationManager) mContext.getSystemService(Application.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(mProvider, 60000, 100, mAttLocationListener);
boolean gpsEnabled = mLocationManager.isProviderEnabled(mProvider);
2) You can still get rough estimates using location information stashed in wi-fi

Related

Why is mock location jumping back to real position

I added a test provider using LocationManager.GPS_PROVIDER as provider name like described here
https://mobiarch.wordpress.com/2012/07/17/testing-with-mock-location-data-in-android/
In Google Maps app, I see location jumping between mocked location and real location, and then back to mocked location.
Why is jumping to real location and how can I stop it?
Maybe I misunderstand how to use mock locations. I haven't found any official documentation available.
You most likely have your location settings configured in a way that your phone (and apps) can use both the location from the GPS sensor and the location from the cells and wi-fi. Since the coming of the Fused Location Provider, the way the system fetches your location got a bit murkier.
When you mock the position you are only able to mock the GPS sensor readings (this is also true for when you mock the position through the simulator settings).
So when the system feeds Google Maps with a position from the GPS sensor it gives it the fake one, and when it provides the position from other sensors it will be the real one.
To test that I'm correct, you can switch location settings to "Device only" and you should only get the fake positions.
Unfortunately there's no way to mock the other sensors readings.
Turn off Wi-Fi scanning / Bluetooth scanning in the Location Settings to stop jumping to preserve mock location.

get location just from GPRS Network Provider Android

I've developed an app that receives the location from both GPS_PROVIDER and NETWORK_PROVIDER, however the NETWORK_PROVIDER returns the best values retrieved from WIFI and GPRS, without having any control over it. I need to get the value returned by the GPRS location listener even when you have WIFI active, so I can use it to dismiss the fake locations from other apps.
Is it possible to do this?
At the moment I'm testing this solution Disable / Check for Mock Location (prevent gps spoofing) , I'll let you know if it solves my issue
Unfortunately it is not possible, no.
You can do something like this:
final LocationManager locationManager = getLocationManager();
final List<String> providers = locationManager.getProviders(true);
if (providers.size() > 1) {
providers.remove(LocationManager.NETWORK_PROVIDER);
}
But you don't have the option to distinguish between a cell or a wifi 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.
Constant Value: "network"
Source: http://developer.android.com/reference/android/location/LocationManager.html#NETWORK_PROVIDER
What you can try is to use this solution. However, since this doesn't seem to be documented I'd be careful relying on it because it might break in future OS versions or might not work on every device.

Getting Speed using Google Play Location API

I am using fused location provider from the new GooglePlay API(LocationClient class). But the method Location.GetSpeed() is not returning correct speed (shows 0). I read that I have to use LocationManager class to get the speed, but when I tried LocationManager a new problem occured. The location manager NetworkProvider is not working, here is a thread with the problem http://code.google.com/p/android/issues/detail?id=57707 .
So what is the best way to get the speed of movement. I tried calculating it distance/time but it is not accurate..
The only sensor that delivers speed is GPS.
Wlan and GSm cell Tower locatining cannot deliver speed.
If you need speed, you have to make sure that GPS is used exlusivley as Location Provider.
You cannot use NetworkProvider for that task.
If speed is an important requirement, which has higher priority than battery consumption you have to stay with GPS Provider only. You have to avoid the fused location provider.
Its technically not possible to have speed without GPS.
I also encountered this problem when I was using Google Play Location API,
I hope this can help.
It returns 0 because your device cannot get a lock on the GPS, or cannot connect to the GPS.
I tried to get the speed using an older lenovo device and it returns 0 because it cannot lock on a gps.
I tried using a samsung galaxy nexus and it returned my speed(has a better GPS sensor).
The GPS sensor in your phone might not be good or you are in an area that has a weak GPS signal such as inside a house or building.
Even if you use the locationManager to get the speed if you are not connected to the gps, your getSpeed will still return 0.

Why couldn't I get GPS coordinates in a remote place?

I went on a trip somewhere remote and I didn't have mobile access but I thought that my GPS would work anyway since a GPS transmitter just relies on satellites. I have the following code to get GPS location:
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
I tried to record my GPS coordinates and they ended up empty.
Is there something that I am not doing correctly or that I don't understand?
What can I change so that my phone can record raw GPS data with or without network access?
A GPS receiver needs to have several GPS satellites above the horizon, in order to receive the signals it uses to calculate its longitude and latitude. Each satellite broacasts this ephemeris information as part of its data stream, but a standalone receiver might take several minutes to scan through the available satellite frequencies from a "cold start" (where cached ephemeris information is out of date or incorrect for the current location).
GPS receivers on cell phones often implement "carrier assisted GPS", where the cellular network pushes the up-to-date GPS satellite ephemerides out to the handsets from time to time, so the phone already knows which satellites are in view at any given time/location without having to do a search.
If you don't have cellular network access, your phone might be programmed to fall back to a satellite-by-satellite search for usable signals, and might take longer to get its first GPS fix (if it can get one at all without carrier assistance).

Android Location Wifi doesnt work after rebooting

I am using this code to get the location provider and location.
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
mBestProvider = mLocationManager.getBestProvider(criteria, false);
mLocation = mLocationManager.getLastKnownLocation(mBestProvider);
If I turn off the GPS, the location is by network, but if I reboot the phone(so I loss the last position known) and with the 3G data connections off. So I am only using WIFI, I cant get any provider thus therefore any location. However google places app can locate me. I think it might be getting the lastknownlocation.But in that case my others applications should be able to get that location. Any idea whats happening?
The way you are calling this it will return all providers enabled or not because you are passing it false which is probably your intention but have you checked the return string?
mBestProvider = mLocationManager.getBestProvider(criteria, false);
You might be getting the gps provider, or you might be getting the network provider, I have learned not to trust the criteria mechanism because it seems to work differently per carrier and device (I have had some weird bugs reported because of this)
So I always ask specifically for gps and network providers and check last known for both, then use an algo to determine the best one to use.
The network provider can use cell or wifi hotspot/routers to determine location (google keeps a database of wifi information) so it's possible to get a fix with just wifi, not saying that is whats happening but it could be.
If that bears no fruit then it's possible that they are simply caching the last location update in preferences, some applications do that. To test the thesis, failing all of the above just leave the phone in that state and move to a very different location with the same properties if possible, should only take 2000 meters or so. If your app still reports null and places reports the old location you have your answer.
If places did report the newer location with wifi, and your app cannot (assuming you actually verify you are getting the network provider) then there is a chance they are using a private API via the Google Location Server (GLS) / MASF server via partial cell / wifi info but that's at the extreme end of the tin foil curve.

Categories

Resources