Show map markers five/ten miles from users current location - java

I've been looking around countless tutorials and stack overflow posts and found nothing on this subject. I'm trying to allow users to set a numerical value (i.e. 5, 10, 15) of miles and then only showing map markers which are within that distance of the users' current location.
So, I have the users location value and I have a database of markers each with their own lat/lng values. What I want to do is:
Get users' current location in Lat/Lng.
Get the required distance value (5, 10, 15 miles).
Get all the map marker location which are 5 miles away from the users' location.
Hide all other markers that aren't.
It's pretty standard functionality when using Google Maps as a user but I just can't find any documentation on it at all. Could any provide any helpful links or some sample code?
I've been looking into LatLngBounds and I believe I can use this in my solution. Am I looking down the right path?

I would first find the min latitude and longitude and the max latitude and longitude using a distance formula (see http://www.movable-type.co.uk/scripts/latlong.html ). Then use the answers from Android - How to get estimated drive time from one place to another? to find those which match in terms of driving distance (which will be less than or equal to the min/max).
By finding the min/max lat/long, you reduce the overall number of calculations you will need to do.

Related

fused location API sometimes returns freak values, how to identify and discard

I'm developing an app that tracks walks, bicycle rides, car rides etc. I need precise info, so I basically would like to use only GPS. Still most sources I found recommend using Googles fused API e.g. for power saving reasons, so I went for the fused API.
Now once in a while (once or twice a month) I get one freak value among thousands of good ones. a few of them I got near railway stations, where the freak value is at another railway station, several kilometers away, so I assume it is a wrong interpreted WiFi based position.
Here's one example, where I ride my bicycle from the river towards the main railway station located east of the river. Once I arrive at the main station, I get no position for 126 s (I asked for every 10 sec, so I probably lost the GPS signal), and then suddenly I get a freak GPS value at another railway station 3450m away on the other side of the river. The reported accuracy for the freak value is 20 m.
The problem is that I cannot easily identify and filter these freak values.
Calling currentLocation.getProvider() always returns "fused", which is not very helpful.
Also Location.getAccuracy() returns typical values below 100m.
So today I filter based on evaluating speed combined with unrealistic changes in bearing, but I'm afraid I might also discard good samples in the process.
I scanned a lot of Stackoverflow, but strangely enough I didn't find any relevant answers yet.
I now feel like moving to the old framework location API and use GPS based data only. But is that really necessary, or does anybody have an idea how to avoid getting the freak values, or alternatively how to easily identify and discard all wifi based positions?
And will using the framework location API have bad battery life as a result?

Spring Data - MongoDb finding nearest locations around a route

I've a model contains geojson points. Finding nearest with spring data is quite easy but how can retrieve nearest location for a giving route?
I am getting the route information from google:
http://maps.googleapis.com/maps/api/directions/xml?origin=48.208174,16.373819&destination=48.340670,16.717540&sensor=false&units=metric&mode=driving
The route information from the maps googleapi is broken down into steps that have a start location and end location with latitude/longitude coordinates.
Computing the distance of the points in your model to all the start/end locations in the route would give you a measure of how far the point is from the route. The minimum 'distance' from the route start/end points would be the nearest location to the route.
You can optimize the computation by discard any points when the computed distance is greater than the previous minimum cumulative distance.
Google maps api returns 'steps' of the route, which has coordinates of the edges of that stretch.
You can use those edges to create extrapolated points on that straight stretch. Lets call them p1,p2,p3,p4...pN.
Then you run $near query in your database for these points, you will
get nearest locations around that route.
Open street map database gives information of coordinates of the route,
which you can use to supplement your data.
Detailed answer here : Get exact geo coordinates along an entire route, Google Maps or OpenStreetMap
First, you need to get this result and then put it in some array that contains Lat+Lng.
Second, create a method in your repository that contains the parameter you want search by with the term "Within".
Example:
List<MyObject> findByLocationWithin(Box box);
This method represent the respective condition:
{"location" : {"$geoWithin" : {"$box" : [ [x1, y1], [x2, y2]}}}
If you need more information you access the follow link:
http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongodb.repositories.queries
https://docs.mongodb.org/manual/reference/operator/query/box/

calculate accumulated distance using GPS in android

I am a new user and is new to android programming.
I am trying to creating a android application that calculate distance a user traveled using a GPS. one of the examples I can think is like a treadmill where it shows the accumulated distance. except the user will be moving around and using a gps to see how long he walked/run.
i can activate a gps, using LocationManager and LocationListener to get a longitude and latitude. but i do not know how to go from there
all my research shows how to calculate distance traveled between 2 points, A to B in a line,shortest distance. but i wanted to have a real-time accumulated distance no matter in which direction the user is going. or how fast.
i do not understand how the logic/math behind the calculation so it is hard for me to come up with a solution. the get.DistanceTo and DistanceBetween also calculate distance in a linear line right?
i also heard something about a accelerometer to use with a GPS. but based on my research so far(not too in depth) it also shows a single location, but i also do not know how to calculate distance from there. or how does it works with GPS
does i have to use longitude and latitude or others?
i'm quite weak in programming but this is a task i have to complete. Thanks
The Google Distance Matrix API
Can't take credit for the answer, I got it from Another post
I would stick to the GPS data and not worry with the accelerometer. Then you would have to record the position in defined intervals and just add the distance to the last point every time you check. The closer you want to get to the real distance the more frequently you have to check. You could then make the interval dynamic e.g. check less often if you go faster.

Android Algorithm for find all Geopoints within a given distance

In my naive beginning Android mind I thought the way to do this would be to loop through each of the objects checking if proximity falls within X range and if so, include the object. This is being done with Google Maps and GeoPoints.
That said, I know this is probably the slowest way possibly. I did a search for Android Proxmity algorithm's and did not get much really. What I am looking for is best options with regard to this the more efficiently.
Are there any libraries I have not been able to find?
If not, should I load these Location objects into SQL then go from there or keep them in a JSONArray?
Once I establish my best datastructure, what is he best method to find all Locations located with X miles of user?
I am not asking for cut and paste code, rather the best method to this efficiently. Then, I can stumble through the code :)
My first gut feeling is to group the Locations by regions but I'm not exactly sure how to do this.
I could potentially have tens of thousands of datapoints.
Any help in simply heading in the right direction is greatly appreciated.
As a side note, I reach this juncture after discovering that a remote API I had been using was.. well.. just PLAIN WRONG and ommiting datapoints from my proximity search. I also realized that if just placed on the datapoints on the phone, then I could allow the user to run the App without internet connection, and only GPS and this would be a HUGE plus. So, with all setbacks come opportunnities!
The answer depends on the representation of the GeoPoints: If these are not sorted you need to scan all of them (this is done in linear time, sorting wrt. distance or clustering will be more expensive). Use Location.distanceTo(Location) or Location.distanceBetween(float, float, float, float, float[]) to calculate the distances.
If the GeoPoints were sorted wrt. distance to your position this task can be done much more efficiently, but since the supplier does not know your position, I assume that this cannot be done.
If the GeoPoints are clustered, i.e. if you have a set of clusters with some center and a radius select each cluster where the distance from your position to the cluster's center is within the limit plus the radius. For these clusters you need to check each GeoPoint contained in the cluster (some of them are possibly farther away from your position than the limit allows). Alternatively you might accept the error and include all points of the cluster (if the radius is relatively small I would recommend this).

Calculate real time distance traveled using google maps

There is a requirement to find the real time distance traveled using google maps. This should be calculated by the phone app itself. When I mean real time, I mean for example if the user is traveling to point A, the user can get to the point in many ways, what I want to do is calculate the total distance the user has traveled real time and not just assume and calculate the distance between the two points (which would not give the correct answer).
I googled around for this problem but could not find any method in doing so.
I personally thought of storing the longitude and latitude on the phone in a list and after the user reaches the destination the distance is caluclated using these points. However this means that I have to decide the interval in which these points are stored (every 1 min or so), which would mean that I would place location points in the list even though the user was actually still on the same road, which is quite unnecessary. Unless if anyone knows how to store the points at the appropriate time or some other solution
I am well more or less stumped on this problem, any help is really appreciated
The mobile platform is Android
Thanks,
MilindaD
I think the best solution is to save the position each X seconds, and then calculate the total distance iterating between them, and to get the time, you just need to see the diference between the last point and the first one.
This is how gps tracking apps work.
Hope this helps ;)
I did it once and it is fairly simple. Use a service with a LocationListener. On every onLocationChanged() save the current Location, At the end you can calculate with Location.distanceBetween() all distances between these saved Locations.
Please keep in mind that it becomes more accurate with faster tracking. For a walk you need less updates than driving a fast car. This can be set with minDistance and/or minTime in LocationManager.requestLocationUpdates().
you could try takeing the start point (IIRC their Long and Lat) then the end point and working out the euclidean distance between the two (see http://en.wikipedia.org/wiki/Euclidean_distance ).
I guess you what a better reloution then two point throgh, so take a third (or more) reading and work out A->B then add B->C.
Repeat for the resaloution you need.
to get the time of the journey. start a clock and stop it at the end (again you could take intermittent points if you wanted)

Categories

Resources