Hello,

I have been working on trying to draw a geochart markers map with data from 
a database for the last few hours and just can't seem to make it work. I 
hope somebody can give me hand.

Here's what I have so far: I have a main php file "index.php", in which I 
send a SQL request to my database. I save the results in the array $row, 
that I use to create the "rows" of the map I want to create.
Here's the code:

$markers = array();
$markersize = 2;
$markercolor = 5;

do {
        $markers[] = "[{v:'".$row['strasse_strassennummer']." 
".$row['plz']." 
".$row['stadt']."',f:'".$row['stadt']."'},".$markersize.",".$markercolor.",'Verbund:
 
".$row['verbund']."'],";
    } while ($row = mysql_fetch_assoc($query));

The data for the rows is saved in the array $markers, which is then encoded 
into JSON and written in a JSON file.

//Json encode
$markers = json_encode($markers);
    
$fp = fopen('jsonkarte.json', 'w');
fwrite($fp, $markers);
fclose($fp);

A php file gets the contents of the JSON file. The last comma of the file 
is deleted (to correspond to the syntax wanted by geochart):

<?php
$string = file_get_contents("jsonkarte.json");
$anzahlzeichen = strlen($string);
$pos = strrpos($string, ",", -1);
$string = substr_replace($string,'',$pos,1);  
echo $string;
?>

Finally, the data is imported into the js file with AJAX:
function drawMarkersMap() {
    
    var jsonData = $.ajax({
          url: "jsonkarte.php",
          dataType:"json",
          async: false
          }).responseText;
          
    // Create our data table out of JSON data loaded from server.      
    var data = new google.visualization.DataTable();
    
    data.addColumn('string', 'City'); 
    data.addColumn('number', 'Color');
    data.addColumn('number', 'Size');
    data.addColumn({type:'string', role:'tooltip', p:{html:true}});
    
    data.addRows(JSON.parse(jsonData));  //Found this solution on the 
Internet...   
};

This solution is not working and, since there are no error messages, I have 
no idea where I have to look for the errors. I am thinking it could lie in 
the syntax I use in php to create the array $markers, but I am at a loss 
about how to change it for the better...

I would be very grateful for your help. Many thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to