I am creating a location app that requires user location to be updated to my server on the move. I would like to use Little Fluffy Location library for this situation.
To understand the process:
Can somebody tell what will happen when I switch of GPS/Network service in my phone - will fluffy location library handle this situation? Or do I need to handle this manually in my APP?
In the example given in their site: https://code.google.com/p/little-fluffy-location-library/
They register location library to call every 1 minute.
What will happen if just use:
LocationLibrary.initialiseLibrary(getBaseContext(), "mypackagename");
Will it receive lat/long when ever the location is changed automatically? Also they claim it battery saver too? update location frequently wont the battery die?
3.I would like to know will it take location based on GPS or Network?
Thanks!
Download library project and client side project that is given on your given link. I hope you will get your answer.
Run client side project in android eclipse and install android apk in your phone and then check yourself for switching off GPS/Network.
Use refresh() to get latest location and locationInfo.lastLat for lattitude and locationInfo.lastLong for longitude.
It selects best provider.
Yeah it consumes battery power more than simple application because we are getting location.
You will get all answer if you download projects. I just downloaded projects and now i will start work on it.
Related
after researching the Android Location FusedLocationProviderClient I am very confused about what you should and should not do!
The use case is: The App holds different locations with latitude and longitude. While the user is walking around the app (with the phone in the pocket, screen off) needs to track if he is close to one of the locations and plays a short beep when closer than a defined range.
Would the Geofence option the best solution? These locations will also change during runtime and periodically - they might also be more than 100. Any suggestion?
I am also thinking about a background service to handle all this when the device moves. This would be more flexible and allows for the reload of the locations as well. Any thoughts?
Thanks!!
You don't actually need to build a background service to monitor if a user is close to a location. There is already a geofence provided by Google. It uses fusedlocation provider internally.
Please refer this
You can combine this with a FusedLocationProviderClient and subscribe to location updates. This way you'll get location updates as well.
Just simple as that.I dont want to find new coordinates every 10 minutes or meters.I just want to click a button and get my coordinates for this exact moment/place where i am.Every tutorial i've seen its old.New android versions require permissions to use GPS or Network.I am trying to implement those but nothing seems to work.
Any solutions?
Thanks in advance
I just want to click a button and get my coordinates for this exact moment/place where i am
That's not possible in general. The device may not know the user's "coordinates for this exact moment/place". You are welcome to call getLastKnownLocation() on LocationManager, or perform equivalent sorts of lookups with Play Services' fused location provider, but they may return null. Usually, to find out where the user is, you request location updates, then react when you get a location fix.
Every tutorial i've seen its old
These sample apps (for the fused location provider) and this sample app (for LocationManager), from my book, should be up to date.
New android versions require permissions to use GPS or Network
All Android versions require permissions to determine the user's location, for blindingly obvious privacy reasons. This has been the case since before Android 1.0, and it should remain the case for the foreseeable future.
I am trying to implement those but nothing seems to work
Then ask a fresh Stack Overflow question, where you provide a minimal, complete, and verifiable example demonstrating your problems.
I have referred many questions on this topic, but it seems some of my requirements are missing:
I want to get the GPS location at ~0.0001 accuracy
Don't want to use internet; Though GSM/CDMA network is ok
Should be obtained programmatically when the app starts
Should be quicker, say within a minute (like iPhone, which probably works in Airplane mode as well!)
The code should work in most of the devices
The phone may switch-on/off anytime and travel any distance
Is there any way to get just the co-ordinates with above mentioned requirements? Any sample code snippet will be much appreciated.
Checking various apps like "Locate Me", "Maverick", which claim to show offline locations. But in various scenarios without internet, they don't give track the location (in India).
I have referred plenty of old/new questions inside/outside SO. Below are few:
Is it possible to have the gps location while offline with the nexus
7?
Does GPS require
Internet?
How to get current exact location in android without internet
connection?
[Note: I am asking this question on behalf of my Android team and will be happy to clarify the details if asked for. Should you feel that this post belongs to Android.Stackexchange, then kindly move it.]
1. I want to get the GPS location at ~0.0001 accuracy
You can listen only to GPS provider and discard a location when it doesn't have the minimun accuracy you want:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 5, myLocationListener); // "myLocationListener" must be an object from a class that implements LocationListener
// "myLocationListener" implementation of LocationListener.onLocationChanged
public void onLocationChanged(Location location)
{
int MIN_ACCURACY = 5; // in metters
if ((!location.hasAccuracy()) || (location.getAccuracy() > MIN_ACCURACY))
{
// discard this location and keep listening to new location readings
}
else
{
// that's a good reading!
// do somethings you want... blah, blah, blah...
// stop updates when you get the location to preserve users' battery.
locationManager.removeUpdates(myLocationListener);
}
}
2. Don't want to use internet; Though GSM/CDMA network is ok
Yes, GPS works totally off-line. Android can make use of internet ONLY to update A-GPS data cache and provide faster reads in cold-start updates.
3. Should be obtained programmatically when the app starts
Then call item locationManager.requestLocationUpdates on mainActivity's onCreate event.
4. Should be quicker, say within a minute (like iPhone, which probably
works in Airplane mode as well!)
Keep in mind that iPhone works with "high quality hardware". Android can be run on crappy devices. So it'll depend of:
The device's hardware quality;
The number of satellites that are visible in the sky at that moment;
The age of almanac and ephemeris data on gps cache;
GPS can fail to read satellites because user is inside a building or something.
5. The code should work in most of the devices
What is the oldest Android's API you want it to run?
6. The phone may switch-on/off anytime and travel any distance
I didn't get it. What is your concern about this?
------------------------------------------------------------------------------
Update 1:
"...I would like to use Android 4.0 and above..."
I've tested GPS features from Android 2.3 to 5.0 devices. Everything runs pretty fine on all of them.
"...I have observed that 1 geo-coordinates based demo app which was working in other devices, din't work in my LGG3 with Android 5.0. Any idea on that?..."
Did you check GPS permissions on Android settings? (Maybe it's disabled) Or can be a hardware issue? Did you try in another similar device?
"...Suppose the GPS is showing correct location in New York,
I switch off the phone and then switch on after reaching to London,
then will it still show correct location (without internet)?..."
Sounds you're confusing things: reading a GPS location is one thing. Showing that location into a MAP is another different thing!
You don't need to be connected to the internet to do GPS location reading. But, if you want to show that location into a MAP, probably you're gonna need internet (to load map resources, etc.).
If you nedd to stay collecting GPS locations periodically (let's say, from 10 to 10 minutes), then it will be better to use AlarmManager to schedule a timer that will "finger" your app and say "hey, time to make a GPS reading!".
"...Also what is your opinion about the latest Fused API?..."
I've tested it and used it for a while, but I gave it up. It needs that Google Play Services be installed to work (not a problem, most users have it on their devices). But if you need ACCURACY (as I do), it will not work. It uses "fused sensors" (accelerometer, gps, wifi, compass, etc...) to try to get user location with minimum power possibile. Sometimes, it says you're 10 miles away from where you're really is. I couldn't make it work fine to keep the "path" where user has been. But it really saves battery.
Suggestion is to use Google Location Services
It takes the best possible and accurate location as accurate as it can at current moment. It automatically (with configuration of course) takes best current accuracy too - whatever is available GPS, network, internet, GSM/CDMA/LTE... It also cashes last known location so, basically, you know it every moment - the best what you can.
Of course you have to realize that each service provides its own accuracy and in it's own time. Look, for example, GPS Test App on Android and see how accuracy increases with time and used satellites.
Also Location Services is good for you because it simply provides coordinates - just as you asked and hides a lot of work to determine what real service to use based on time and accuracy. However, of course, if none of the services on your particular device and location can give you required accuracy then there is no way to get it. That's why services also provide accuracy measurement.
Here is another link
Use fused location API provided by Android SDK.Implement fused location in a Service and call it in your application MainActivity.
I've been working on an app that needs to be location-aware, and I've noticed that there are two (or more) methods of receiving location: with Google Play services (as seen here developer.android.com/training/location/retrieve-current.html#GetLocation) and with Location Manager, Providers etc. (as seen here http://www.vogella.com/tutorials/AndroidLocationAPI/article.html#locationapi_criteria).
What is the difference between these methods (if there is any)? Which one is more accurate?
edit: ok, I see that I sent the wrong link on the first thing. Won't this code (http://developer.android.com/training/location/receive-location-updates.html) give me location updates? Generally, what's the most accurate way to get my location?
The one with the GPS is accurate and that which is based on Network is not. Google Play Service use FUSE api to get the GPS location first, if the location is found (that's great), otherwise it will try to get location fix from Network Tower. In Short the one with GPS is accurate
The first method provides the details of LastKnownLocation. ie. the last location received from GPS or network provider when you or other apps accessed the location services. After that there are chances you moved a lot and it need not be your current location. So if You are planning to create an application that requires accurate location tracing, You should fetch the location as in the "Vogella" method. If the current location is unavailable, you can try using the last known location (As a plan B :-)).
Im writing an android aplication in which is required the actual location of the user, but I'm having trouble acquiring that location.
I'm using a LocationListener to listen for the location update, via Wifi (NETWORK_PROVIDER).
The problem is I don't get an update, and I imagine it only happens when I change network. If I don't get updates, I can use lastKnowLocation but it does not provide me with the actual user's location.
Is there a way to force a location update, via NETWORK_PROVIDER?
Cheers
Even better, I suggest you look at the new Location APIs in Google Play Services.
There's a training class for them as well.