Support » Fixing WordPress » Parsing PHP array in Javascript array in JS file.

  • I’m trying to create markers in google map JS API V3.
    Each post in blog has a variable with city name that is collected to
    an array $cities.
    the code in gmap.js, that is loaded in header of myblog uses array cities:

    google.maps.event.addListener(mgr, 'loaded', function() {
    // These markers will only be visible between zoom level 1 and 7
            mgr.addMarkers(cities, 1, 9);
    // These markers will be visible at zoom level 6 and deeper
            mgr.addMarkers(dotss, 10);
    // Making the MarkerManager add the markers to the map

    PHP code in loop.php returns me needed data in the array,

    var cities = [];
    foreach( $clean_cities as $city_r ) {
    echo "cities.push(" . $city_r . ");\n";

    the result is
    var cities = [kiev,kharkov,lvov,odessa];
    If i write or assemble in the same way this array directly in gmap.js everything works perfectly.
    But if I generate or manually write this array in page body – nothing works, at the same time other variables and arrays (such as latitude and longitude) defined in page body are perfectly accepted by gmap.js.

    Does anybody know what’s the problem in here?
    Thanks in advance for answer.

  • The topic ‘Parsing PHP array in Javascript array in JS file.’ is closed to new replies.