Gmaps javascript arrays

I am new to javascript, so in this example there is geometrycontrols.js (for global controls) and markercontrol.js (for marker controls)

my problem is defining arrays where the "data" is stored ...

in the link, I see the savedata function, but I have no idea how to work with this function ...

on the other hand, in test.html, if I have access to run Glog and output "data", and let me think that this comes from an array ...

My goal is to save the coordinates and other attributes of the mysql database, and when I find out where the "data" is the easy part.

if someone worked with this example (or not), can help me, I am grateful

ps: i'm really new to javascript: P

edit1: I was away for a while, and now I'm concentrated in the field of geometrycontrols.js specifically in: GeometryControls.prototype.saveData = function(opts){ var me = this; if(opts.allData === true){ //me.saveAllData(); } else { //construct a json data record var geomInfo = opts.geomInfo, index = opts.geomInfo.index; var record = geomInfo.storage[index];
var recordJSON = {}; recordJSON.type = record.type; recordJSON.coordinates = [];

//determine geometry type, and copy geometry appropriately
if(record.type === "point"){
  recordJSON.coordinates.push({lat:record.geometry.getLatLng().lat(),lng:record.geometry.getLatLng().lng()});
 alert(recordJSON.coordinates);
} else {
    alert("is not point");
  var vertex;
  for(var i=0;i<record.geometry.getVertexCount();i++){
    vertex = record.geometry.getVertex(i);
    recordJSON.coordinates.push({lat:vertex.lat(),lng:vertex.lng()});

  }

}

//add title and description
recordJSON.title = record.title[0];
recordJSON.description = record.description[0];

//TODO add styles 
recordJSON.style = ""; //TODO}  //TODO Make separate prototype function?function postData(data){
//TODO 
me.debug(data);
//alert(recordJSON.coordinates);
//alert(data);
};postData(me.serialize(recordJSON));}; `

When I warn (recordJSON.coordinates), outupt is [object Object], and I don't know why, theoretically this array contains coordinates ...

+3
source share
2 answers

Here is the code I used to send data to MySQL. It uses a bit of jQuery to create ajax magic (a line starting with a dollar is jQuery).

function postData(data){
me.debug(data);      
var dataString = JSON.stringify(data);   
me.debug(dataString);
$.post('storage.php', { data: dataString });   
}; 
postData(recordJSON);

As you can see, I changed the way the recordJSON object is sent to the postData function: I removed the serialization function.

Then create a PHP file (called "storage.php" in my case) and put it in it:

<?php
$received = json_decode($_POST['data'], true);
echo "just received " . $received['name'];
?>

PHP, , .

jQuery, , , .

+1

Source: https://habr.com/ru/post/1750946/


All Articles