Being a programming novice, I have been stuck on this for a few days. All code below I have researched from this site and others to solve the problem with no success.
I can successfully load data onto Google Maps from a json file on my server with:
map.data.loadGeoJson('http://www.h...........com/geojson/164_surveydata.json');
map.data.setStyle({
editable: false,
draggable: false,
strokeWeight: 2,
strokeColor: '#686868',
});
I can then edit the polylines, moving nodes to new positions.
I then attempt to save the edited map data layer with a panel button onclick function:
function saveData() {
map.data.setStyle({
editable: false,
strokeWeight: 2,
strokeColor: '#686868',
});
map.data.toGeoJson(function(data) {
var jsonData = JSON.Stringify(data);
});
$.ajax({
method: 'POST',
url: 'http://www.h..........com/savegeojson.php',
data: {'data' : jsonData},
success: function(response){
alert( response );
},
error: function (response) {
alert('error'+ response);
}
});
}
I use the same php requirements that successfully posts data to a SQL database on my Server, thus assuming i can do the same to access files on the same server. My php file is as follows:
<?php
require __DIR__ . "/getdb.php";
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
$json = json_decode($_POST['data'],true);
if (json_decode($json) != null) { /* sanity check */
$file = fopen('http://www.h.....com/geojson/164_surveydata.json','w+');
fwrite($file, $json);
fclose($file);
} else {
// handle error
}
?>
The idea is to load the json file into google maps, edit polylines etc, and then save the data back to the same json file.
Any help is greatly appreciated. Also any tips as to where to place errorhandlers(?) will also be awesome.