Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Saving Location GeoPoint to DB

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?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Saving Location GeoPoint to DB

Hi Tom,

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

Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Saving Location GeoPoint to DB

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.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Saving Location GeoPoint to DB

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.

Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Saving Location GeoPoint to DB

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

Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Saving Location GeoPoint to DB

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???

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Saving Location GeoPoint to DB

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

Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Saving Location GeoPoint to DB

:) Perfect, simple solution. Thanks!

Return to “Issues”