I have an Android IoT device running Android 5.1.1 on Rockchip RK3288 that as name implies can connect to a WiFi network but doesn't have a GPS or a Cellular module. Whenever I try to access location and find the best location provider it always return me as a 'Passive' provider and hence i have no way of getting my current location.
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
I am a bit perplexed that the device has an active network connection but NETWORK_PROVIDER isn't available.
Try Google Geolocation API.
Google Geolocation API use wifiAccessPoints and cellTowers too. As you said device don't have GPS and Cellular module you need to use WifiAccessPoints for it.
For WifiAccessPoints you need to pass all your nearest wifi connection data. For E.g In android when click on WIFI it shows list of wifi near to you. So, you need to just pass all that wifi list to WifiAccessPoints so it returns the location of your device.
You can Pass Parameter "considerIp": "true" so using your Ip Address it get the current location of your device.
For My Opinion use Get Current location through IP Address which return the Highest Accuracy ratio for current location.This is also said by the Google Maps Geolocation API document.
For more information you can refer Google Geolocation API which also provide sample data so that you can check the result from here.
I hope this will give you some hint or get some idea to actually you want to achieve.
Related
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.
The GDK developer guide states:
Local providers obtain location data from the Glass hardware such as GPS_PROVIDER and NETWORK_PROVIDER.
However this doesn't seem to be the case. I tried logging all available providers with:
Log.d("LocationDebug", mLocationManager.getAllProviders().toString());
The result is:
[remote_gps, remote_network, network, passive]
So no local GPS. If I try anyway with the following code:
mLocationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
The app crashes and the following gets logged:
java.lang.IllegalArgumentException: provider=gps
As described in the location and sensors developer guide, you should avoid referring to specific location providers, such as GPS_PROVIDER by name. Instead, use a Criteria-based approach or iterate over all location providers to ensure that you include the "remote" providers that retrieve locations from a Bluetooth tethered device running the MyGlass companion app. This will get you the most reliable location information.
I'm looking for a way to know the country-level location.
How to do it on a phone, or devices that have cellular network connectivity or GPS is clear. But what about devices that don't have that?
I know from Google Analytics that Google has that kind of location information,
How?
How can I get that information as well? Maybe from the play-store locale or something?
By "Tablets" I mean devices that have no GPS and no GSM / cellular network connection.
10x
Use the WiFi aproximated location. It checks your IP adress and tries to locate it geographically.
please see this or this.
a quick summary of the WiFi location method form one of the posted links:
How it works: Unless you opt out, your phone is periodically sending anonymous data to Google with, among other things, your last known location and any Wi-Fi network you were connected to at the time. The accumulated data builds on a database begun by traveling Google Streetview cars that recorded Wi-Fi networks available along their routes (the cars no longer do this).
When using this method, your application will ask for the COARSE LOCATION permission on installation.
Since there's no clear indication (at least none that I've found) whether or not Google estimates location based on IP as a last resort, my 'getCountry' logic would be as follows:
Location location = LocationClient.getLastLocation()
If (location == null) location = getLocationByIp()
where getLocationByIP() will use a publicly available, RESTful free web service such as http://freegeoip.net/
Open to suggestions here. If line 2 is redundant I will be happy to drop it.
Cheers
(Y)
I have written a small app that receives the location from mobile 3g/wifi by using locationManager & NETWORK_PROVIDER parameter.
according to google's api it will get the location i wish (the other option is using the GPS_PROVIDER)
what i really desired was the WIFI location. I wanted to see its behavior and how the phone gets its location (i.e with wireshark)
in order to do that, i changed into flight mode & activated wifi.
then, i launched the app and clicked the button which starts the NETWORK_PROVIDER location service by calling the requestLocationUpdates function with time parameter = 10.
what that actually happened is that i managed to get the location but saw no traffic at all in wireshark.
could it be that Google gives me the approx. location in advance, when connecting to the wifi? (its the only explenation)
If so, is it possible to clear that cache, or whatever data it have stored, and force the phone to get a new (but the same) location?
Thanks in advance,
Eran.
Have you tried re-booting the phone, just so to remove any cache files which might be storing the location?
Since NETWORK_PROVIDER use cell location, wifi ssid and their signal strength to get your GPS coordinates.
Since you are in flight mode and cannot get cell location, just try to switch the connected wifi , maybe google service will be invoked to get new location.
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.