fabio_na
(Fabio Na)
August 16, 2018, 3:15pm
1
HI I’m trying to save\update a geopoint in my table, I have used also the code in the docs with no result.
https://backendless.com/docs/js/doc.html#data_relations_with_geo_points
with this code no geopoint is created neither. I’ve tried my code, with geoPoint I’ve tryed an existing object geopoint and also only the id of an existing geopoint.
function updateLocation(placeObjectId,geoPoint){
var place = {
objectId : placeObjectId,
location : geoPoint,
phone : "525252"
}
Backendless.Data.of( "Place" ).save( place )
.then( function( savedObject ) {
console.log( “Place instance has been updated” );
})
.catch( function( error ) {
console.log( "an error has occurred " + error.message );
}
);
Am I doing something wrong? It doesnt work how I think it works? thanks
Hi Fabio,
I checked the docs and it appears the JS section has not been updated to reflect the changes in the product (the Android and iOS are up to date though. I will get the docs changed asap. Here’s a sample code which shows how to create a relation between a data object and a geopoint.
var geopoint = {latitude:32.77, longitude:96.79}
Backendless.Geo.addPoint( geopoint )
.then( function( savedGeoPoint ) {
Backendless.Data.of( "Person" ).findFirst()
.then( function( firstPerson ) {
Backendless.Data.of( "Person" ).setRelation( firstPerson, "location:GeoPoint:1", [ savedGeoPoint ] )
.then( function( count ) {
console.log( "count is " + count );
} )
.catch( function( error ) {
console.log( "setRelation error " + error );
})
})
})
The code does the following:
Saves a geopoint
Retrieves a data object
Creates a relationship between the data object and the geopoint from (1)
For more details about the setRelation
API, please see the API doc: https://backendless.com/docs/js/doc.html#data_relations_api_set_add_js
Regards,
Mark
fabio_na
(Fabio Na)
August 16, 2018, 9:15pm
3
wow man, didn’t expect a solution so fast. It worked perfectly. Is also possible to make a one to many relation? I’ve tryed
Backendless.Data.of( “Place” ).setRelation(parentObjectId, “location:GeoPoint:n”, [mapId1, mapId2])
.then( function( count ) {
console.log( “relation has been set”+count );
})
.catch( function( error ) {
console.log( "server reported an error - " + error.message );
});
console pointed me to use geoPoint:n instead of geoPoint:1 but it didn’t work
What you did is correct, but it will work only if the relation column doesn’t exist yet. If the column is already defined as 1:1
and the code uses location:GeoPoint:n
, you will see an error. So you have the following options:
Define the relation column in console as one-to-many and use location:GeoPoint
in the code
or
Delete the column in console and always use location:GeoPoint:n
in the code.
Hope this helps.
Mark
fabio_na
(Fabio Na)
August 16, 2018, 9:35pm
5
Mark, what can I say, thanks, quick and perfect answer. thanks a lot. Keep going guys you rock