Best Practice to Save GPS Coordinates - android

I'm developing my first android app and one of the features is tracking the user's route. At another point in the app I'm going to have a review and bring up another map to plot the locations. I implemented the LocationListener and set the minDistance to 50 meter and everything is working correctly. In the onLocationChange I add the new location to a list. I'm wondering what, in your opinion, is the best way to save this list? Currently I'm just writing the list to the local SQLite db, but I'm wondering if this best or if there are other alternatives I should explore.
Thanks

Related

Fetch accurate intermediate Location points in background and calculate Distance of Starting and ending locations in Android

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.

Better way to update PolyLine track from GPS readings

In my app I have a Service which receives location updates and stores them to a database. I also have a Fragment which displays a MapView and a PolyLine of all recorded waypoints from the database.
During recording, the Service notifies the Fragment about new waypoints so the Fragment can update the PolyLine. The problem is that when the user navigates away from the app the app the Service keeps recording waypoints to the database, but now the Fragment doesn't get updated since the Fragment is paused. So in onResume I create a new PolyLine, read all the waypoints in the database and add them to the database.
This is all working fine, but it doesn't really feel like it's optimal from a performance perspective to create a new PolyLine and re-add all the waypoints (there could be thousands!). I guess I could just re-add any new waypoints that are not already in the PolyLine, but I wanted to see if anyone here has an alternate solution? Is there any way to keep the Fragment "alive" and updating its PolyLine even when the app is in the background (as long as the service is running)? Or is there a better way to do this?
Recreating the polyline is probably inevitable, but here are some things you should think about doing if performance becomes an issue:
Put a time limit. When recreating the polyline, only fetch the data in the last hour or day (test and you'll be able to determine the best value here), and offer an option to extend that period. This will make it more understood by the user that the data needs some time to load, and that the app will use more resources.
Aggregate the data while saving them. This should reduce the disk space used to save the points in the database (very important for low end devices) and improve on the performance when rebuilding the activity.. These are some tips for what you can do to reduce the number:
Check 2 points behind and see if they are a straight line. If so, delete the middle one. That should remove a lot of data recorded when the user is in a car or walking a long distance
Check if the last set of points (5 or more) are in the same area, that way you can get rid of a lot of data. So if a user is just waling in his home or workplace, you can just save one point for that without loosing too much data, which shouldn't really be a problem in most (99%) of the applications.

How to determine which persons are close to you from a database

Let's say we have a few 100.000 people and they all share their location.
Their location is stored in a database online as Geopoint.
If I open an app on my device and I only want to show the let's say 50 closest people, what would be the way to approach this.
I know I can just retrieve every bodies location from that database and check the distance for every single device. But that seems to be not a very effective way. Especially if it would become millions of people.
What is the proper way to approach this?

Is it possible to make a location based app?

Would it be possible to make an Android application that works based on location, for example when you get to work the app might turn off WiFi or Bluetooth or change any other system settings in order to save battery or something?
The app would require the user to enter in locations where they want the app to begin working, like their address, and when the phone sees that they have arrived at this location it will start working. I want to do this but I don't know where to start.
I already have some android app development experience.
Yes absolutely this is possible. I have worked on approx three application with same concept.
You need to create a center point and define a radius for the same.
Then you need to calculate the distance of you current location with that particular center point and if your distance is less than or equal to radius, trigger to switch on the services you want.
In android you can use
LocationManager class
For collecting the data. If you want some more help I can provide the same too.
I've played around with a concept like this on the Windows Phone for a while, and I think this would work for Android too.
Basically, you'd use the GPS of the device to detect your location, and then compare this to the locations saved by the user. If the location comes within range of a saved setting, perform an action.
GPS usage however drains battery, so you'd have to experiment a bit with making this an efficient method.
Have you tried GeoFencing, its really cool. It lets you define a center point, and a radius. Once the user enters this radius you get callback or a pendingIntent. You can do what you want in your callback.
You can get addresses of your customers and build geofence around their locations.
Edit :
If you choose to not use GeoFenceing (for what ever reason), note that LocationManager is highly buggy and unstable on most mobile phones (Samsung).
Instead use LocationClient, which takes care of all the crap LocationManager leaves with us to deal with and provides location faster, lesser battery and customized accuracy.
Edit :
If anyone tries to convince you otherwise, check this out. A video from google developers and their talk about why LocationManager sucks, and why they knew and helped us figure out the value Sensors add to the entire solution.
Edit : Design of your solution
You need 2 geofences
1) Outer, you can hard code this to a imaginary 500 m from office. From then on you can start looking for wifizones
2) Once a wifizone is found, save the gps and the distance from his address point. That is your inner radius.
1 Geofence is defined by your install, 2nd geofence is defined by your runtime.
2nd Geofence and be used henceforth to disable GPS (only incase you decide to use LocationManager). If not you wont need this, LocationClient will do what it does best.

Android Location services

I need to create a database of gps coordinates by walking some trails and periodically storing coordinates. What would be the best way to get gps coordinates quickly sent and stored on the phone in an array of some sort so I could later access the coordinates. I need to be able to save them on the phone and then get them back to the computer. Any tips will be helpful. thank you
Here's a great page on acquiring location and I'd suggest you store the locations received in a Sqlite database, which means the location data will persist between each time you run the app, which seems like what you need.
As each location comes in, you can store them in the database, and from there it's easy to handle them, e.g. pass them on. Not sure what you mean by "get them back to the computer, as you don't say why or in what format.

Categories

Resources