WHERE DEFAULT_RADIUS_SEARCH_KM = 1, but I am not getting the results sorted by distance. I am always getting the same order in results no matter which origin geopoint I use.
We researched this issue. Changing the current implementation so that the result is sorted automatically was quite difficult. We came up with a following workaround: when you run a geo search in radius, results (geopoints) will be returned sorted. Since geopoints can have related data objects in the metadata, it would allow the same level of functionality as what you originally asked about.
There is a bit of work we need to do to get this done, but it would be a lot more realistic on our side.
In your approach, I must have all the information that is currently in my data tables as metadata in geolocation, and I also will lose all the benefits of using data tables. Besides, it doesn’t feel like the right way to handle data. I thought one of the main reasons to use geoqueries in data tables would be to get sorted results …
No, that is not true. A geopoint may have one metadata property which points to a data object. There is no reason to duplicate all the object properties in the metadata. More details are in the doc:
I have checked the documentation and you are absolutely right, it is possible to relate a geopoint to an object through metadata and the search is working. This is my code:
BackendlessGeoQuery geoQuery = new BackendlessGeoQuery();
geoQuery.setLatitude(myLatitude);
geoQuery.setLongitude(myLongitude);
geoQuery.setRadius(Double.valueOf(DEFAULT_RADIUS_SEARCH_KM));
geoQuery.setUnits(Units.KILOMETERS);
geoQuery.setCategories(Arrays.asList("Leisure", "Churchs"));
geoQuery.setIncludeMeta(true);
Backendless.Geo.getPoints(geoQuery, new AsyncCallback<BackendlessCollection<GeoPoint>>() {
@Override
public void handleResponse(BackendlessCollection<GeoPoint> response) {
List<GeoPoint> points = response.getCurrentPage();
for (int i = 0; i < points.size(); i++) {
GeoPoint point = points.get(i);
//Object object = point.getMetadata("place"); //how to retrieve this as a custom object?
System.out.println(place.getName());
}
}
@Override
public void handleFault(BackendlessFault fault) {
callback.onError(new Exception(mContext.getString(R.string.error_places_found)));
}
});
I am able to retrieve the geopoints, but I have two doubts:
I don’t how to retrieve the metadata property that points to my object already casted as a custom object. In this case, is called “place”. In the metadata, it is a HashMap. Is there an utility in Backendless Android SDK that could map from HashMap t the custom class? An example in the Android SDK would be extremely helpful for me in this case.
If I don’t specify any categories in the geoquery, it doesn’t get any results. Is there a way to set the geoquery to search in all existing categories?
About my second question, I think it would be useful to search in all categories. Is it something you may consider to include in the future?
I have another doubt. If my metadata custom object has a one-to-one or one-to-many relation with another object, is there a way to set the geoquery to retrieve that relation too?
If you use that call first and pass the complete list in the search API, it would do what you want. However, from the performance perspective, it may not be the best approach - it an expensive call.