I need current location of user in my application on based on that location I will search on database!
I am getting current location right now by using example code given but it is not accurate. If no GPS I get location by network provider but it shows sometime 2 location names at the same location. If it is showing one name 1 min before after 2 min it will change to another location.
This code is look but do not know how to use it. Please help me out in this regard!
What is the simplest and most robust way to get the user's current location on Android?
I need to get the location name.
Network location is not as reliable as GPS location, so you might get some fluctuation. That's even more true if you're relying on wifi APs.
You may try to average locations or wait to see if it stabilises in some location in particular, or show the most common location (i.e., the one reported most of the time).
Related
EDIT: As Francky Vincent said, I see that price depending on distance is not advisable. I have 4 parts but only 3 are the prices depending heavily on the distance (and planning to change it later). But, I still need to get current location as I have 'x.x KM from you'.
A little bit of intro:
When I was around somewhere with low coverage, I open the Grab app and able to get my current location, even though will take too much time. My own app have no problem with location but at the same location, it will get the last known location - and I don't want that since one of my app feature is the price is according to the distance between current location and target.
For the codes, I just using the examples provided for Fused Location by Google in Github and seems like it's not enough? My aim is to get current location instead of last known - just like the Grab app.
Is that possible using Fused Location? Or did the example provided can achieve what I want but I missed something important?
I referred to this question but still got clueless. Really new with this feature.
The strategies that I can come up is:
Start app
Check permission
Request permission
Get current location
Save the latitude and longitude in SharedPreference
Stop getting location
Please help. Thank you!
I don't need to be too precise. I want to know location can be an area of the user in one country. I tried using the location service getLastKnownLocation with the update through GPS. If the getLastKnownLocation is unknown, the time it take to get the result is quite a bit of time. I am working on the weather application, I don't need to have the street name. Is there another way of getting the result more faster.
you can get the last known location for more detail read here last Known Location
or you can request a location updates every period of times you set request locaion updates
it's pretty straightforward
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 have an Android app where I should somehow clearly distinguish between whether user has not moved for an amount of time or location was not resolved during that interval. As I understand in both cases I will not receive any update if I requestLocationUpdates().
Does anybody has an idea on how to implement this?
The sample case is:
I've got 2 valid and accurate locations: 1 from GPS and 1 from network; Good, that's exactly what I need.
One minute has passed: the user may have gone to a kind of underground station and lost gps/network (and ability to resolve location) OR may have not moved at all;
Now I have to decide whether the location is perfectly relevant (user not moved) or I have no location at all (all providers lost). But how? Seems like in both cases I receive no location updates.
Try using LocationClient.getLastLocation. You can store this location and check against it later.
After few hours of testing outside of house, when i came back to my house i found that GPS is enabled but was not getting location fixes inside the building.Hence its onLocationChanged method couldn't get called.
Problem: How to know that GPS is not getting any location fixes as device continue to sense your location in "trying mode".By trying mode i mean the situation where it is not coming to any result even after 20 to 30 minutes still it declared it self as enabled (blinking in status bar).
How one could know that the GPS doesn't get location so switch to another provider like Network_Provider.
In short i want to get my device to conclude something that GPS can find location fix for sure or you have to take location by another means.
I hope at least someone can give me idea about how to deal with that.
The link below has an awesome tutorial, of how to get the location from GPS and/or Network.
It uses a timer task, which analyzes if there is a GPS location in a specific period of time, assume 20 seconds. If not, it will return the location from Network as the current location. If there is a location from GPS, then it will compare which update is new (latest), and return that.
What is the simplest and most robust way to get the user's current location on Android?