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.
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.
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 :-)).
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.
I newbie in location and trying make service to show my current location and another one location saved previously. And what the difference of using LocationListener vs LocationClient?
The LocationListener connects to the LocationManager and retrieves your location. This worked and works fine.
The LocationClient is a new way to implement this while some of the rest gets deprecated. It features more functions.
Both methods actually works.
Location Manager was introduced in Android SDK and can be used as a feature of android.
Location Client is something that's part of Google Play SDK and is introduced in the recent Google IO 2013.
You can understand that since LocationClient is the latest, it is more efficient in getting the location with minimal energy(battery drain) with greater accuracy.
Reasons to use LOCATIONCLIENT because:
The location update behavior is very abnormal and wont work as you expect. i.e. The location updates get stuck when switching networks. (It keeps giving you some old location)
The location client wont work on modified android versions of the android OS, as it requires Google play services.
Location Client might be good on the battery of the phone but it won't be good with giving you timely accurate location updates.
I recommend good old Location Manager as I don't find location client reliable at all.
Note : There is no point of saving battery if you are not even getting your current location in a location based application.
I use network provider to get location in Android application. Sometimes I found the location would not be changed even after I arrived at a new place. At the same time, I found the locations were changed in Google Map. So I quit and restarted my application, and the locations wasn't changed either. But after a long period, or I reboot the phone, I could see the new location.
Does any one know what's the reason ? I have used getLastKnownLocation() to get the latest location in my application.
Update:
When this problem happened, I found the cellid and LAC was changed while the location wasn't changed. So it's very strange. I think Google Map may use cellid & LAC to get the location directly, so it can get the correct location.
More update:
When this problem happened, I used the cellid and LAC to get the location via HTTP POST request from Google server. This location was correct.
BTW, I found my question was like this question: Android network location takes hours to update location
I wouldn't trust getLastKnownLocation(). In my experience this isn't reliable.
You'd be better off requesting location callbacks using LocationManager.requestLocationUpdates(). If you only need the location once you can then unregister for the callbacks using LocationManager.removeUpdates() after that. If your application needs to be notified when the location changes then you can register for callbacks with a reasonable minium-time and/or minimum-distance parameter (based on whatever your application requires.