Last active
August 29, 2015 14:04
-
-
Save eiriksm/413ecfc181032e6f6fa4 to your computer and use it in GitHub Desktop.
Creating nodes with services module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLocationAndPost() { | |
'use strict'; | |
navigator.geolocation.getCurrentPosition(function (position) { | |
var url = 'http://example.com/enpoint' + '/node.json'; //endpoint URL | |
var lat = position.coords.latitude; | |
var lon = position.coords.longitude; | |
var date = new Date(); | |
var timestamp = Math.round(date.getTime() / 1000); | |
var node_object = { | |
"type": "some_type", //set this to your content type | |
"uid": 1, | |
"field_geo": { "und": { 0 : { //my geofield is called field_geo | |
"wkt": "POINT (" + lon + " " + lat + ")", | |
"geo_type": "point", | |
"lat": lon, | |
"lon": lat, | |
"top": lon, | |
"bottom": lon, | |
"left": lat, | |
"right": lat } } | |
}, | |
"title": "Big brother sees you", | |
"body": { "und": { 0 : { "value": "Put some body value here if you want" } } }, | |
"created": timestamp, | |
"status": 1 // Set to 1 for Published. O for unpublished. | |
}; | |
$.ajax({ | |
url: url, | |
type: "POST", | |
data: node_object, | |
success: function() { | |
alert('Success!'); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment