Support Topics Documentation Slack YouTube Blog

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)

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

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?

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.

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?

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

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

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&lt;BackendlessAPI.Geo.GeoPoint&gt; callback = new AsyncCallback&lt;BackendlessAPI.Geo.GeoPoint&gt;(



result => {





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




//relate current user with a geopoint



currentUser.SetProperty("location", result);



AsyncCallback&lt;BackendlessUser&gt; updateUserCallback = new AsyncCallback&lt;BackendlessUser&gt;(



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



Let us know if it helped to you.

And I also recommend you to migrate to 4.x

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&lt;BackendlessUser&gt; updateUserCallback = new AsyncCallback&lt;BackendlessUser&gt;(
            user =>
            {
                System.Console.WriteLine("User updated");
            },
            error =>
            {
                Dispatcher.BeginInvoke(() => ProblemBlock2.Text = error.Detail);
            }
            );


           
            Backendless.UserService.Update(currentUser, updateUserCallback);

Hi,

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

This is very misleading.

Thanks
Makis