Update GeoPoint always create new one.

I’m working with JavaScript SDK and I need to update latitude and longitude of a existent GeoPoint. I’m using Backendless.Geo.addPoint passing an existent objectId but I alway get a new GeoPoint.

var geoPoint = new GeoPoint({
 objectId : place.location.objectId, // existent objectId
 categories : place.location.categories,
 latitude : parseFloat(place.location.latitude),
 longitude : parseFloat(place.location.longitude)
});


Backendless.Geo.addPoint(geoPoint, new Backendless.Async(function onSuccess (success) {
 // Always is a new GeoPoint
 console.log(success);
}, function onError (error) {
 console.error(error);
}));

Can you help me?
Thanks.

Hi Eduardo,

I just checked the source of the addPoint method and it looks like it does the PUT request:
https://github.com/Backendless/JS-SDK/blob/master/libs/backendless.js#L2050-L2056

Our REST API supports two methods PUT and PATCH:
https://backendless.com/documentation/geo/rest/geo_updating_a_geo_point.htm

The PUT implementation is a complete replacement, it removes the geopoint and saves it again. A fix would be to check if geopoint has objectId, then do PATCH, otherwise use PUT. I will open an internal ticket to make that change. Until then, you’re welcome to tweak the library to make it work how you want it.

Regards,
Mark

Thanks Mark.

I made this change in backendless.js

var method = (geopoint.objectId.length > 0) ? 'PATCH' : 'PUT';


return Backendless._ajax({
    method      : method,
    url         : this.restUrl + '/points',
    data        : JSON.stringify(geopoint),
    isAsync     : isAsync,
    asyncHandler: responder
});

But I get a new error:

[Error] XMLHttpRequest cannot load https://api.backendless.com/v1/geo/points. Origin http://localhost:9000 is not allowed by Access-Control-Allow-Origin.

This is a CORS problem. Do you have “*” in this setting in console?

https://backendless.com/documentation/manage/mgmt_cross_origin_requests.htm

Yes, I have.
Could it be the PATCH method on /geo/points endpoint?

Hi Eduardo,

Correct signature for PATCH method for GeoPoint is:

geo/points/:id

where id - objectId of GeoPoint.

Regards,

Denys

Hi Denys,

I made this change in backendless.js

var method    = (geopoint.objectId.length > 0) ? 'PATCH' : 'PUT',
    objectId  = (geopoint.objectId.length > 0) ? '/' + geopoint.objectId : '';


return Backendless._ajax({
    method      : method,
    url         : this.restUrl + '/points' + objectId,
    data        : JSON.stringify(geopoint),
    isAsync     : isAsync,
    asyncHandler: responder
});

and works perfect!

Thanks so much!