Backendless Support
 
Waiting for user's response

Problem with User-to-geo relationship through api c#

I try to relate a user object and a geopoint with no luck.Location property is of type Geo Relation:

GeoPoint.Here is my 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);

//save geoPoint in backend

AsyncCallback<BackendlessAPI.Geo.GeoPoint> callback = new AsyncCallback<BackendlessAPI.Geo.GeoPoint>(

result =>

{

System.Console.WriteLine("Geo point saved - " + result.ObjectId);

},

fault =>

{

System.Console.WriteLine("Error - " + fault);

});

BackendlessAPI.Backendless.Geo.SavePoint(geoPoint, callback); //geopoint saved in backend

//relate current user with a geopoint

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);

(or Backendless.Data.Of<BackendlessUser>().Save(currentUser, updateUserCallback);----> does not work either)

Leave a Comment

Comments (8)

photo
1

Hi Nicos

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"

https://github.com/Backendless/.NET-SDK/blob/4.0/Backendless/Data/DataStoreFactory.cs#L253

Regards, Vlad

photo
1

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?

photo
1

It is better to create new applications with Backendless 4.x, because support of 3.x will be terminated.

There is some difference https://backendless.com/docs/android/doc.html#migration_from_3_x_to_4_x this document is for android, for .NET coming soon, but the difference is mostly the same as for android.

photo
1

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?

photo
1

Could you provide your AppId please, it help us to investigate your problem

photo
1

Yes of course. Here it is 240E7D36-4DB3-5B9E-FFCE-10AB68C0BA00

photo
1

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.

  1. GeoPoint geoPoint = new GeoPoint(latitude, longitude);
  2. currentUser.SetProperty("location", geoPoint);
  3. 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

  1. GeoPoint geoPoint = new GeoPoint(latitude, longitude);
  2. AsyncCallback<BackendlessAPI.Geo.GeoPoint> callback = new AsyncCallback<BackendlessAPI.Geo.GeoPoint>(
  3. result => {
  4. System.Console.WriteLine("Geo point saved - " + result.ObjectId);
  5. //relate current user with a geopoint
  6. currentUser.SetProperty("location", result);
  7. AsyncCallback<BackendlessUser> updateUserCallback = new AsyncCallback<BackendlessUser>(
  8. user => {
  9. System.Console.WriteLine("User updated");
  10. },
  11. error => {
  12. Dispatcher.BeginInvoke(() => ProblemBlock2.Text = error.Detail);
  13. }
  14. );
  15. Backendless.UserService.Update(currentUser, updateUserCallback);
  16. },
  17. fault =>
  18. {
  19. System.Console.WriteLine("Error - " + fault);
  20. });
  21. BackendlessAPI.Backendless.Geo.SavePoint(geoPoint, callback); //geopoint saved in backend

Let us know if it helped to you.

And I also recommend you to migrate to 4.x

photo
1

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);