I am using Google-Play-Services to track user activities. In case of a walking activity or bicycle activity I want to calculate the rough speed the user is moving. Is there any simple method? Location updates by Google-Play-Services are sometimes quite inaccurate since there is no good GPS signal in particular areas.
By the way, I realised the GPS location is getting very accurate when I start the google maps navigation application. I wonder how to get a location with the same percision without starting Google Navigation.
If the Location was created by GPS, then use location.getSpeed().
Related
There may be similar questions regarding this topic,But I need your thoughts and suggestions on some specific requirement.
Here is my need -
We are developing one app which tracks User's trip.
The app will start collecting the location of that user in background,When user 'Starts' his trip from App.Background Service will be fetching locations on the basis of user's movement in specific time duration.
When User 'Stops' his trip from App,We are calculating distance traveled by user with help of all recorded locations(With Google Distance calculating API).
The App works fine in ideal case.
But main challenge is -
In some scenarios,We are not able to fetch exact and precise location of User. Scenarios affecting is - No internet,Data plan with 2g/3g,some specific areas where GPS is not returning accurate data etc.
Incorrect data of lat-long causes incorrect Trip distance and route.Which is main problem with the App.
Please,any one can suggest the best alternative/Suggestion for this?
P.S. - We have tried GPS,Network,FusedLocationProvider.
EDIT 2 --
We have implemented logic on basis of accuracy and distances.Got nearer points. And just came across one useful api from Google that corrects some location points which are distracted from actual Roads. Posting here for reference of others...
Snap to Roads Api from Google
this is a complicated topic.
One consideration you have to take. Android Oreo limits background services and that what you want to achieve won't work.
I would do is this (and it is the recommendation from Google)
When someone starts the trip (the user is aware of it), you must launch a on going notification with a foreground service , don't rely on background services anymore. Check the feature "Start Activity" in Google Fit App.
As for not having signal, or accurate GPS, well... it is a geographical problem!, there is nothing you could do. Or, maybe you can, using the LocationProvider.
FusedLocationProvider is fused within every app that requests locations updates.
Read this out, and see if that helps you.
https://developer.android.com/guide/topics/location/strategies.html
Try to mix GPS and Accelerometer
If you detect that GPS stopped working, turn on accelerometer. If GPS is turned on again, calculate distance again with it. This way you can have route with GPS parts and accelerometer ones. The bigger GPS parts, the more accurate data will be
How to get more accuracy by GPS_PROVIDER
Basically if the accuracy of a location isn't acceptable throw it away. The next one will be better.
For a school project, i have to do an Android project (i am new to Android coding) where i must track the user location and record his travelled distance.
For this, i use the Google Fused Location API.
I am having good results concerning the tracking, but it is only working when the app is in the foreground.
I have to continue to track the user location even when the phone is sleeping, and calculate his travelled distance.
I made some researches and found some solutions with AlarmManager, or with the requestLocationUpdates using PendingIntent. But i can't figure out what is the best to use in my situation.
The "only" thing i want to do while the phone is sleeping is to continue getting his location and increment a float with his distance, so i can update the UI when the user is back on the app screen with his correct distance travelled.
What is the best way to do this in my case ?
Thank for your answers.
I've ran into a little problem and I don't feel like I'm informed enough to overcome the hurdle.
In essence, I'd like to figure out whether someone is moving over a threshold of say, 40 kmh (~25mph). I get GPS coordinates at designated intervals and compare the distances, which all works fine.
My question is, which method of getting GPS coordinates would work best for this application? Using the Network, using GPS, or both (like, check if the network is connected, else use GPS)?
The summary is, which is the most accurate method?
I'd use the fused location api in this case. In addition, if you want to know if someone is moving you could use the activity recognition of google play services, it requires much less effort and you can even filter by activity: only with car for example (if you want to track over the 40km/h it's unlikely someone is moving on feet).
I am self learning Android programming at the moment. I was about to write app that will display my location on map without using GPS.
I have tried using NETWORK_PROVIDER and found that my accuracy is constantly at 2000 even in city area with a lot of wifi around the area.
I would like to know how could other map application (e.g. GoogleMap) is able to achieve high accuracy without using GPS.
They use GPS. Or they lie about their accuracy. Ever seen the big blue circle around your position in Google Maps? That means they think you're somewhere in that circle, and are guessing about actual position.
The only way to get accuracy is to use GPS/GLONASS signals. A-GPS can help to fix position quickly because it provides info about which satellites are in view from your phone cell position (your device don't spend time trying to get signals from satellites not in view).
The 'High accuracy' mode is just a lie from Google to know your position all the time to monetize you in perverse ways
If you are using the network provider to fetch the location they are not very accurate. SO its not a good idea to fetch the accuracy of your position using
network provider. Its best to use GPS to get the location updates. You can use GetAccuracy() method of Location class and see for the value it returns.
Let Say if getAccuracy() retruns 25 then you can leave this value wait for another gps value which is more accurate.
I don't think it is possible w/out actually using a LocationProvider, but figured I would see if anyone had any thoughts.
Basically I have an app which has a PageView w/ a fragment which contains a the new MapView 2.0
I can easily pull the my Location by way of getMyLocation from the GoogleMap object.
I have had issues in past; across some devices, using both NetworkLocation & GpsLocation providers at the same time. Since I can just pull my location from the GoogleMap, I get a simple way to check my location.
My only issue is that I can watch for map panning to update the map by handling onCameraChanged, but it does not handle the location changing inside the map.
My current implementation is that I have a MapView and LocationProvider.. The location provider is in a service, and is set to update based on a user determined time (1,5,10,15,30,60 seconds). The activities connect to the service via AIDL, if there is >0 connected activities the locationProvider is enabled, if not, it turns off. This really has little bearing to the Google Map though, if we don't handle loss of GPS signal the same as Google maps, the location we get is different than the Google maps.
My first of 3 options:
get a provider, and pass that in where I could get a callback on location change (did not really want to do this). This would involve be by way of LocationSource..
Second option
get the current location provider that I am using in my current service, and each time it updates, just grab the location from the map. I suppose this would work, but seems a bit redundant, and still have issue of managing LocationProviders when screen is turned off etc.. (Don't have to do that w/ google map)
The other option would be to have a service that is passed an interface to the map object which can query the current location. And do so every x seconds that the user has indicated.. I can reuse most of the service for this, would just have to set it up to keep calling.
The other thing I was thinking of was maybe just using a passive provider to update the current location, from using the current MapView.
My only other consideration is Spoofing: I want to try and prevent location spoofing. I can make it so we don't allow Mock Locations. But that does not mean it can't be spoofed still.
So... Any thoughts would be greatly appreciated. Thanks.
Google introduced the new LocationClient and associated LocationListener (the previously introduced OnMyLocationChangeListener interface is now deprecated).