How to connect between Geolocation and Users table .

Hi,
I’m trying to connect between Geolocation and Users table, I could not find in the docs a way to do it directly,
so what i did is :

Map<String, Object> meta = new HashMap<>();
meta.put("userID", U.currentUserID);



Backendless.Geo.savePoint(lat, lon, meta, new AsyncCallback<GeoPoint>() {



@Override
public void handleResponse(GeoPoint geoPoint) {

BackendlessUser current = Backendless.UserService.CurrentUser();

current.setProperty("location", geoPoint);

Backendless.UserService.update(current, new AsyncCallback<BackendlessUser>() {




@Override
public void handleResponse(BackendlessUser backendlessUser) {

Log.i("backendlessUser : ", backendlessUser.getUserId() + " set successfully");

}




@Override
public void handleFault(BackendlessFault backendlessFault) {}

});
}


@Override

public void handleFault(BackendlessFault backendlessFault) {}

});


But, this will cause problems in later search…
In addition to that , there is a way to overwrite the same user location (not in Users table).
Thanks

Hi Xcode,
Please look at documentation https://backendless.com/documentation/data/android/data_relations_with_geo_points.htm. Will it satisfy your interest?
Artur

Hi Artur,
I checked this example, but there is no way to use “save” method with map to add data into “Users” table.
Also I cannot understand why when i’m trying to get the property “location” from Users table returns null .
Thanks


  GeoPoint point = new GeoPoint();
                point.setLatitude(40.7148);
                point.setLongitude(-74.0059);
                BackendlessUser user = Backendless.UserService.CurrentUser();
                user.setProperty("location", point);


                Backendless.Persistence.of(BackendlessUser.class).save(user, new AsyncCallback<BackendlessUser>() {
                    @Override
                    public void handleResponse(BackendlessUser user) {
                       
                         BackendlessDataQuery query = new BackendlessDataQuery("distance(40.7148,-74.0059, location.latitude, location.longitude ) < km(10000)");


                        Backendless.Persistence.of(BackendlessUser.class).find(query, new AsyncCallback&lt;BackendlessCollection&lt;BackendlessUser&gt;>() {
                            @Override
                            public void handleResponse(BackendlessCollection&lt;BackendlessUser&gt; response) {
                                Log.i("test","name :" +  (GeoPoint)response.getData().get(0).getProperty("location")); // return null
                                Log.i("test","name :" +  response.getData().get(0).getProperty("location")); // return null
                                Log.i("test","name :" +  response.getData().get(0).getProperty("location.latitude"));// return null
                               Log.i("test","name :" +  response.getData().get(0).getProperties());//Everything returns to correctly except location
                            }


                            @Override
                            public void handleFault(BackendlessFault backendlessFault) {
                            }
                        });
                    }


                    @Override
                    public void handleFault(BackendlessFault backendlessFault) {
                    }
                });

As I see, location is a relation. Relations are normally not fetched during find. You have to explicitly tell which relation you have retrieve. Please refer to documentation
https://backendless.com/documentation/data/android/data_relations_retrieve.htm

Thanks Artur!

The problem occurred because I had to mark the “auto load” checkbox.

For my second question there is a way to overwrite the same user location ?

Hey Xcode,

Yes, you can

    For update exist geoPoint which is assigned to user [url=https://backendless.com/documentation/geo/rest/geo_updating_a_geo_point.htm]https://backendless.com/documentation/geo/rest/geo_updating_a_geo_point.htm[/url] For assign a new geoPoint to user object [url=https://backendless.com/documentation/data/rest/data_relations_with_geo_points.htm]https://backendless.com/documentation/data/rest/data_relations_with_geo_points.htm[/url]
Regards, Vlad