What Backendless are you using 3.x or 4.x ?
And what do you mean when say “with no luck” ? do you get some error? or just relation does not create?
if you are using Backendless 4.x you can not add/set relations via “setProperty” any more
you need to create/update relation via another methods “AddRelation/SetRelation”
Hello vlad i am using Backendless 3.x. Relation is not created and i get this error “java.lang.RuntimeException: java.lang.RuntimeException: failed to load RelatedGeopointsCategorys for com.backendless.datamodel.GeoPoint from database”. How can i set this relation with backend 3.x? Can i or i have to migrate to 4.x where there is the SetRelation method?if i migrate will i have problem with code that was working fine in 3.x version?
First thanks a lot for your help. I understand that i have to create apps with 4.x from now on but since i have already developed my app in 3.x and there isn’t documentation for .net yet how can i solve this problem with setting relations in 3.x?Can you help me? Is my code wrong?
I’ve noticed one point in your code, you have two async api requests, save new GeoPoint and update User with new GeoPoint.
If your goal was add a new GeoPoint to user you don`t need to save the point before update the user, just set new geo point object as user property and save user.
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
currentUser.SetProperty("location", geoPoint);
Backendless.UserService.Update(currentUser, updateUserCallback);
But if you want to create/save a new GeoPoint point and then do some manipulation with the geo point and then set the point into user as relation you have to move snippet of code for updating user to Success Callback of save geo point
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
AsyncCallback<BackendlessAPI.Geo.GeoPoint> callback = new AsyncCallback<BackendlessAPI.Geo.GeoPoint>(
result => {
System.Console.WriteLine("Geo point saved - " + result.ObjectId);
//relate current user with a geopoint
currentUser.SetProperty("location", result);
AsyncCallback<BackendlessUser> updateUserCallback = new AsyncCallback<BackendlessUser>(
user => {
System.Console.WriteLine("User updated");
},
error => {
Dispatcher.BeginInvoke(() => ProblemBlock2.Text = error.Detail);
}
);
Backendless.UserService.Update(currentUser, updateUserCallback);
},
fault =>
{
System.Console.WriteLine("Error - " + fault);
});
BackendlessAPI.Backendless.Geo.SavePoint(geoPoint, callback); //geopoint saved in backend
Ok i took your first example.I get this error “java.lang.RuntimeException: java.lang.RuntimeException: failed to load RelatedGeopointsCategorys for com.backendless.datamodel.GeoPoint from database” and relation is not created!!
Here is the code!!
var latitude = geoposition.Coordinate.Point.Position.Latitude;
var longitude = geoposition.Coordinate.Point.Position.Longitude;
BackendlessUser currentUser = Backendless.UserService.CurrentUser; //get current logged in user
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
currentUser.SetProperty("location", geoPoint);
AsyncCallback<BackendlessUser> updateUserCallback = new AsyncCallback<BackendlessUser>(
user =>
{
System.Console.WriteLine("User updated");
},
error =>
{
Dispatcher.BeginInvoke(() => ProblemBlock2.Text = error.Detail);
}
);
Backendless.UserService.Update(currentUser, updateUserCallback);
I know that this is an old thread but since it is not possible to create User to Geo Relations using the set Property to backendless 4.x and 5.x could you please update the examples that you have in the API documentation https://backendless.com/docs/android/users_relations_with_geo_points.html
The example demonstrates that the user can be linked to geo point by updating the user
GeoPoint geoPoint = new GeoPoint( 48.85, 2.35 );
user.setProperty( “location”, geoPoint );
Backendless.Data.of( BackendlessUser.class ).save( user );