How can I make a geo location query in CBL? - android

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.

Related

Get polygon from longitude and latitude in mobile apps

I am working on an app that have over 2 millions of user. It is going to introduce location based feature. From the very beginning we want to provide the user a location based notification which will be changed based on their location/region. I am using PostGIS and Mapbox technologies. I have a custom polygon which is the indicator of different region. I know I can use a ST_Within of PostGIS to get the polygon info by sending longitude and latitude to server everytime. I am using the folloing function to get the region
CREATE OR REPLACE FUNCTION getRegion(getlng numeric, getlat numeric, OUT outregion text)
as $$
BEGIN
SELECT region into outregion
FROM mypolygon
WHERE ST_Within(
ST_GeometryFromText(
'POINT('|| getlng ||' '|| getlat ||')', 4326
),
geom);
END; $$
LANGUAGE PLPGSQL;
and calling the function by
SELECT getRegion(getlng, getlat);
But as there are millions of user it will increase the load on database server and need to be increased the TPS. Is there any other way to get the polygon/region from point beside using postgis directly? The region polygon is changable, not constant.
There is a method called ray-casting and recently mapbox is supporting query withing vector tiles. Is ray-casting or query within vector tiles will be a better approach for doing the same thing? (Again remember, the polygon is not constant.)
In a nutshell, I actually want to know the best practices using currently by the community to reduce the load on server and save time.
1) You will have to index your polygons using some grid (may be UTM, Google tiles or your own custom grid)
2) Identify grid of user location
3) Now fetch the polygons which lie on the same grid .In the best case you will get only single polygon and you will not have to use ST_Within.
4) Now if you get multiple polygons use ST_Within with only these polygons instead of the entire list of polygons
This Algo will save lot of memory and processing as ST_Within is a very heavy process.
Note: I have been using this approach from past 4 years and it has done wonders in terms of time and memory saving

How to Retrieve FireStore Users Within a Range With GeoFireStore Android

I am currently working on a program which requires containing location of users with Android Studio. In my users collection, I have location informations as geopoints for each user documents. I need to get all users which are in radius range of a circle. I found GeoFireStore of imperiumlabs -https://github.com/imperiumlabs/GeoFirestore-Android- for this geographic location processes. I can set and get location of a document(single user). But I want to define a center and check if there is/are anyone within the range.
As I understand I need to use geo query event listener as follows;
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {...}
It has Key Entered, Key Moved, Query Ready, Query Error methods, but I couldn't manage what and how to use. I need returned informations of documents(users) which(who) are in my defined range. This way, I can show them main user.
For short words; can someone help me about understanding event listeners of geofirestore?
Thanks for your precious time.
After spending more and more hours I finally solved my issue with
public void onDocumentEntered(DocumentSnapshot documentSnapshot, GeoPoint location) {}
in the GeoQueryDataEventListener Interface. This method works recursively until meeting the requirements of query and I put it in onCreate. I just listed document_id's with documentSnapshot.getId() and tranferred them to an arraylist with mList.add(documentSnapshot.getId()) . Hope this can help someone take care.

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

How to get all cities info over a route between two geo points

I have an question that while using Google Direction Api we can get the list of data like city's name, its Lat & Lng etc but the data provided by Api is limited to some extend. It's not able to provide all cities coming with-in that particular route.
E.g. If we try to go for Chandigarh to Delhi, then the route has a fixed result but when we try to reverse that same search i.e. Delhi to Chandigarh, some of the cities coming in previous result get vanished in api's new result, moreover, we just have a limited amount of locations/cities in result while we need the route completely detailed.
Do any of you guys faced this issue before? Is there any other way to match such requirement?
Hope I am understandable.
Thanks.
Use the below url:
https://maps.googleapis.com/maps/api/directions/json?origin="latvalue","longvalue"&destination="destnLat","destnLong"
&sensor=false&avoid=highways&mode=driving&alternatives=true
you have to set the alternatives value to true so it will result different routes available between the source and destination

Find locations that are behind my current location in 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.

Categories

Resources