Find locations that are behind my current location in Android - android

I have some locations (lat & long) and I need to show these locations in a listview. I can do this perfectly.
But now I want to show the locations that are ahead of my current location. That means I want to skip the locations that I have already passed during my driving.
Let me clarify more clearly. we have locations like loc1 (lat,lon) , loc2(lat,lon), loc3(lat,lon).. loc100 (lat,lon). during my driving I like to see the locations (loc1 - loc100). But now I want to hide the locations (between loc1 to loc100) which I have passed from my current position/location. Say, I have passed loc1, loc3, loc5 so I need to skip these 3 locations from my listing in listview. To achieve this, I need to know which locations (loc1 - loc100) are behind my current location (gps current location) so that I can skip that locations.
Any idea? how i can achieve this in my code? Please help regarding this.

I would have two data structures (e.g., LinkedList) of Location objects:
unvisitedLocations
visitedLocations
Your list being shown to the user would be based on the contents of the unvisitedLocations data structure.
Based on your real-time location, you will need to detect proximity to each of the Location objects in the unvisitedLocations data structure based on given radius threshold value that you choose. To do this, you can either register each location with the LocationManager.addProximityAlert() methods (which will fire a PendingIntent when detecting proximity), or loop through the unvisitedLocations data structure and do this on your own - something like:
if(currentLocation.distanceTo(unvisitedLocations[i]) < threshold){
visitedLocations.add(unvisitedLocations[i]);
unvisitedLocations.remove(i);
}
This will give you the list of currently visited and unvisitedLocations based on your real-time locations.
Note that as initial size of the unvisitedLocations grows, performance will become an issue since you'd be looping through the entire data structure contents to determine proximity of location for each real-time location update, which can be once per second from GPS. If performance becomes an issue, you should look into moving the proximity detection server-side and using a spatial database, which has special data structures to make proximity detection far less intensive.

Related

How can I make a geo location query in CBL?

I am using CBL for Android. I have the latitude and longitude values that the user saved earlier. And there are also values for the location the user has marked on the map.
I need to make a query on the database using the location information the user has selected on the map. So if the records in the database are located near the location the user chose, I want to show this.
How can I do that. I have no idea how to query this in CBL. I would be very glad if you could help. Thanks in advance.
There is no out-of-box query support. From discussion thread posted here,
It’s possible to do bounding-box queries without specialized indexes;
for example (pseudocode) loc.x BETWEEN $x0 AND $X1 AND loc.y BETWEEN
$y0 AND $y1. With regular indexes on loc.x and loc.y (as opposed to
R-trees) this isn’t very efficient, but it’s workable as long as your
data set isn’t too large.

3 Android GPS Questions

1) For some reason, the longitude and latitude are slightly different after storing them. For example, when i first find them, they are:
25.171057657111998 and 35.013447496224636 but after I store them , they are
25.1710586547852 and 35.0134468078613. Why is this happening? I store them as floats in an sqlite database, retrieve them with Cursor.getFloat, and print them with String.format of 13 digit accuracy.Can this difference affect the end results in a significant way? I am working with distances <100m (328 feet)
2)I am trying to find the center of a location cluster. Here
http://www.geomidpoint.com/calculation.html
method C says I can just take a simple average if I work with <400km. Has anyone tried it? Is it working? Or should I go for the first, more accurate method?
3) After finding the center, do I need anything else to create a new location object for distance purposes?
To solve this problem you may store longitude and latitude in your sqlite database by this way:
longitude*10^10 , latitude*10^10
when you get them you will divide them by 10^10.
because with 5 decimal is accurate

Android Google Map Finding Nearby Pre-Listed Locations

I have an ever increasing list of places identified by lat/long stored in my database. Now at the UI front there is a screen with a place auto-complete textbox means if I type a location there a drop down will appear with places and when I select the place the camera will move there. Also it is required that I display locations nearby (locations as stored in my database). Now the question is how to do this? I can use
SphericalUtil.computeDistanceBetween()
But the problem is I can't fetch all lat/long from my database and calculate distance without hampering performance.
You would need to compute the distances in your database. There are two basic options:
Implement your own distance method in your database:
If your positions are close to each other and close to the test lat/lng you can use Pythagoras's theorem (a ver basic approach that will not be correct in all the cases)
To address all the possible cases you can implement yor own haversine formula (the haversine formula gives great-circle distances between two points on a sphere from their longitudes and latitudes and is used to compute distances in the SphericalUtil.computeDistanceBetween() method).
Use a GIS database. You can use SpatiaLite for Android and use the ST_Distance function to filter your positions:
SELECT *
FROM yourtable
WHERE ST_DISTANCE(Geometry, MakePoint(yourXcoordinate, yourYcoordinate)) < yourdistance

How to figure out when a gps coordinate is valid in Android

I'm developing an Android app and I need some help to save GPS coordinates for a route... coordinates are very important for my app, so: how can I do in order to get very good coordinates (especially at a first try)? How can I understand whether the position is correct or not? How can I use getAccuracy method or similar to figure out whether the position is wrong so that I have to reject it?
For example: I get a 1st LatLng coordinate but the 2nd LatLng is located 100 meters away from the 1st coordinate, so I guess that is very unlikely that a user can move 100 meters away in a few seconds... how can I create such an alghoritm?
Android Defining a Model for the Best Performance to get location
http://developer.android.com/guide/topics/location/strategies.html#BestPerformance

Display nearby markers in Map Fragment based on location from over 2000 locations?

I have a local database with over 2000 locations that I am trying to search through based on the users location. I only want to display a few markers in the Map Fragment nearby the user, but have so far been unable to find a way to do it.
Currently the database is in the form of a csv file, so I can change it to a different type easily. But I was waiting to do so until I could find a utility that can search the coordinates based on a radius around the user. Anybody have any suggestions?
You can define a LatLngBounds object for some box around the user, and then use bounds.contains(LatLng) to determine which of your locations are in that radius. I've used this method for collections of about the same size as yours and it was fast enough for our purposes. You will be searching a rectangle, not a radius, but since the map is a rectangle, maybe that makes more sense anyway?
This is a tricky topic and solution is not straight forward. I am briefly listing down the steps I have used and this works for well over 100k assets in my case.
Assuming you already have logic to get your current location and lets call if as myLocation.
Add your location data in sqlite file and treat location coordinates as nothing more than float.
Use offset as 0.001 which is roughly around 100 m and use the following in the query.
(myTable.lat > (myLocation.lat - offset) AND myTable.lat < (myLocation.lat + offset)) AND
(myTable.lon > (myLocation.lon - offset) AND myTable.lon < (myLocation.lon + offset))
This should give you the list of assets within a small radius
The trick here is to treat location as float and not really location.
For Offset: http://en.wikipedia.org/wiki/Decimal_degrees

Categories

Resources