Page 1 of 1

Saving Location GeoPoint to DB

Posted: Sun Jan 12, 2014 4:29 pm
by Tom6106181

Hi, I am struggling a bit saving Geopoint to DB.
I am getting the latitude and longitude, but DB is only giving me a bad request.
Image

Event-Collection-DB = Col.location:
codelocation
(geopoint),idx/code
Mapping
code
var map = Appery('map');
var GLat = map.gmap.getCenter().lat();
var GLon = map.gmap.getCenter().lng();
var point = {};
//point['location']= {"latitude": GLat, "longitude": GLon};
//return point;
//return {"[type":"GeoPoint", "latitude": GLat, "longitude": GLon + ']'};
//var point = "[latitude": GLat, "longitude": GLon + ']';
//point = {"type": "GeoPoint","latitude": GLat, "longitude": GLon};

//point[value]= { "latitude": GLat, "longitude": GLon };
//"location": "[" + 48.208 + "," + 16.373 + "]&quot
//point[value]= { GLat, GLon };
//point[value]= {GLat,GLon };
/*var point = {
"__type": "GeoPoint",
"latitude": GLat,
"longitude": GLon,
}; */
//var point = "[" + GLon + ", " + GLat + "]&quot
//point[value]= { "location": [GLat, GLon] };

point[value]= {"latitude": GLat, "longitude": GLon };

console.log(point);
return point;
/code

As you can see, I have tried alot of different options for the mapping. Suggestions?


Saving Location GeoPoint to DB

Posted: Sun Jan 12, 2014 4:46 pm
by Illya Stepanov

Hi Tom,

Is Data Type of the field in collection is set to GeoPoint?
:: http://docs.appery.io/documentation/b...


Saving Location GeoPoint to DB

Posted: Sun Jan 12, 2014 4:49 pm
by Tom6106181

Yes. column = location (type GeoPoint).
EDIT;and I have read the docs, but can not find any solution (eg, all my mapping trials). Please provide an example/tutorial on how to save GeoPoint trough mapping.


Saving Location GeoPoint to DB

Posted: Sun Jan 12, 2014 5:02 pm
by Illya Stepanov

In your code:
pre
var point = {};
/pre
should be an array.

Image

GeoPoint should be formatted like this: [48.208, 16.373] -
you'll need the correct format of the value, in mapping.


Saving Location GeoPoint to DB

Posted: Mon Jan 13, 2014 9:18 am
by Tom6106181

Could please provide an example mapping, according to my vars in my mapping, to create and save the lat, lng to DB as geopoint?


Saving Location GeoPoint to DB

Posted: Mon Jan 13, 2014 9:57 am
by Tom6106181

Mapping:
code
var map = Appery('map');
var GLat = map.gmap.getCenter().lat();
var GLon = map.gmap.getCenter().lng();
var jsonback = {
"__type": "GeoPoint",
"latitude": GLat,
"longitude": GLon,
};
console.log(jsonback);
return jsonback;
/code

DB - column - location (GeoPoint type).

Error msg when saving;
code
Object {__type: "GeoPoint", latitude: 59.957899253328534, longitude: 11.230150673437475} eventNewScreen.js:268
POST https://api.appery.io/rest/1/db/collections/events 400 (Bad Request) api.appery.io/rest/1/db/collections/events:1
/code

To be clear, everything is saving nicely, except the GeoPoint - location.

Suggestions???


Saving Location GeoPoint to DB

Posted: Mon Jan 13, 2014 2:57 pm
by Maryna Brodina

Hello! Try prevar map = Appery('map');
var GLat = map.gmap.getCenter().lat();
var GLon = map.gmap.getCenter().lng();
return [GLon, GLat];/pre


Saving Location GeoPoint to DB

Posted: Tue Jan 14, 2014 10:44 am
by Tom6106181

:) Perfect, simple solution. Thanks!