GPS coordinates using network - android

I am currently working with GPS in my android application.My questions are, 1.Is GPRS needed to get gps coordinates,if want to get coordinates without GPS? 2.What are the settings need to be enabled to to work with gps coordinates using network?

You want geographical coordinates as pair: latitude, longitude. (not GPS coordinates)
Such coordinates and other attributes can be delivered either by GPS, WLAN or Cell-Tower locating.
For WLAN and Cell-Tower (Network) locating you need an internet connection.
For GPS Locationg Provider, ususally you don't need any network (GSM) but there are some Android phones that are strange designed, such that GPS does not work without having an Internet connection while starting GPS.
If you want network locating, you can explicitly set the Location Provider. Set it to NETWORK_PROVIDER:
if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}

Is GPRS needed to get gps coordinates
Answer: Not necessary if you are not using map.
But you have to use following permissions to work with GPS.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
What are the settings need to be enabled to to work with gps coordinates using network
Only enable your wi-fi and GPS on device.

To 1.: GPRS and GPS do not have anything in common. GPRS is a protocol for mobile internet, whereas GPS is for positioning you're phone. GPS doesn't need internet to work!
Anyways, most smartphones nowadays have Assisted GPS (A-GPS), which basically works as normal GPS (without any internet connection), but CAN retrieve information about the GPS satellites via internet for a faster location fix. GPS should still work without any internet connection as far as I know, but maybe there are really provider out there, who messed with the protocol so badly.
Long story short: GPS doesn't need internet!
To 2.: as I mentioned above, you don't need any internet for GPS, so that
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
should work.
But you're question sounds like you wanna obtain coordinates via network positioning. In that case you would need
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
But: ACCESS_COARSE_LOCATION is already implied by ACCESS_FINE_LOCATION

Related

Android Location Not Available when there is no GPS

I would like location information to be available to my App, from GPS if available, and if not from other means such as Wifi.
Location info works fine with GPS, but if I turn
Settings->Personal->Location Mode = Battery Saving
to exercise a non GPS scenario, or just run the App where these is no access to GPS, location information is no longer available to the App.
In my code this test returns false when GPS is not available :
string Provider = LocationManager.GpsProvider;
if (m_LocMgr.IsProviderEnabled(Provider))
Log.Info("location available");
else
Log.Info("location NOT available");
My manifest.xml is set up as follows :
...
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
...
Any ideas please. How can I enable location services when GPS is not available
The answer was simply to enable the Network provider in addition the GPS one.
Provider = LocationManager.NetworkProvider;
if (m_LocMgr.IsProviderEnabled(Provider))
m_LocMgr.RequestLocationUpdates(Provider, 2000, 1, this);
I had misread the permissions documentation. Just because it says that if you use Fine (GPS) permissions you implicitly get Coarse (Network) permissions, does NOT mean that you dont need to enable them both in code.

why ACCESS_COARSE_LOCATION needs to location must be enabled

I am trying to get user location with low battery consumption and without GPS (location). Milimetric coordinates are not necessary for me. So I decided to use
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
and also at this google developer docs https://developer.android.com/guide/topics/location/strategies.html it says:
Permission for ACCESS_COARSE_LOCATION allows access only to
NETWORK_PROVIDER.
I dont actually understand why this API doesn't give user current coordinates without location being enabled. In my opinion, if I use COARSE_LOCATÄ°ON instead of FINE_LOCATION, API should not use location.
I am also trying "Basic Location Sample" at https://github.com/googlesamples/android-play-location/tree/master/BasicLocationSample
You are requesting for user's LOCATION it may be with FINE LOCATION or COURSE LOCATION. User needs to AUTHORIZE the app for doing that.
The only difference is that the device will spend less energy trying to get the user's location and won't get exactly location.

Accessing Gps issue

I am trying to access GPS in my Mobile
using the following code
locationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
loc1 =locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
till yesterday it was working fine now app is not fecthing gps
i have enabled permission in manifest
LocationManager
This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to fire an application-specified Intent when the device enters the proximity of a given geographical location.
You do not instantiate this class directly; instead, retrieve it through Context.getSystemService(Context.LOCATION_SERVICE).
Unless noted, all Location API methods require the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permissions. If your application only has the coarse permission then it will not have access to the GPS or passive location providers. Other providers will still return location results, but the update rate will be throttled and the exact location will be obfuscated to a coarse level of accuracy.
In Manifest File :
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
How do I get the current GPS location programmatically in Android?
http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/
I have had the same problem. I had to re-check my virtualbox network settings. Please double check your settings before assuming your code is the problem.

Android location permissions

In my Android application I'm willing to use GPS locations.
What are the main permissions that I should included in android
manifest file in order to use GPS locations.
In case of lost the GPS signal strength, is there any way to triangulate the position using mobile networks.
Thank you!
The main permissions you need are android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
Only fine location will allow you access to gps data, and allows you access to everything else coarse location gives. You can use the methods of the LocationManager to acquire location data from gps and cell tower sources already, you do not have to work out this information yourself.
If you are targeting API Level 21 (5.0) or higher, you may also need this:
<uses-feature android:name="android.hardware.location.gps" />
This permission should allow your app to use location services through the devices GPS, wifi, and cell towers. Just plop it in your manifest wherever you put your permissions, and it should do the trick. You can find all the other permissions here: (http://developer.android.com/reference/android/Manifest.permission.html)
Here is the code:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I had the same issue and noticed that the code was requesting high accuracy but the manifest had course permissions. I changed it to fine and the error no longer occurs.
Make sure the code and the manifest reflect the same level of accuracy requested and allowed.
So if the manifest has android.permission.ACCESS_FINE_LOCATION the application can request geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high...

how to ACCESS_FINE_LOCATION keeping GPS turned OFF?

I would like to get accurate location from NETWORK_PROVIDER keeping GPS turned OFF in order to save battery. This seems impossible becasue android, when ACCESS_FINE_LOCATION is specified, turns on GPS even when location is not requested to GPS_PROVIDER.
I have added:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
into the Manifest. I needed that in order to avoid android obfuscating accurate position.
I registered updates just using NETWORK_PROVIDER and not GPS_PROVIDER:
myLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
60000, 0, locationListener);
GPS turns on anyhow. How can I avoid it (without forcing the user to disable GPS, that actually works but is undesired)?
Sounds strange, if you haven't requested location updates from the gps-provider, it shouldn't boot up the GPS.
Let me give you a piece of advice though - don't count on the network provider to give you 'fine' accuracy unless you're sitting on a wifi that google knows the position of.
Positioning based on cell towers usually have accuracy of about 500 - 2000m, perhaps 3-500m in city centers.
Use either ACCESS_FINE_LOCATION is you want GPS to be used or ACCESS_COARSE_LOCATION if you don't want to use GPS.
If your positioning technologies are disabled to save power, how can you expect to get an accurate position? That would be like expecting a car to take you to work but not wanting to put gas in it. tanstaafl.
As mentioned above, WiFi positioning can give you pretty good location acuracy if you are around a couple of APNs that Google knows about. Given enough time and enough people using their phones, Google will eventually learn every APN that doesn't move.

Categories

Resources