WordPress.org

Ready to get started?Download WordPress

Forums

Parsing PHP array in Javascript array in JS file. (1 post)

  1. Vrefr
    Member
    Posted 3 years ago #

    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
            mgr.refresh();
            });

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

    <script>
    var cities = [];
    <?php
    foreach( $clean_cities as $city_r ) {
    echo "cities.push(" . $city_r . ");\n";
    }
    ?>
    </script>

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic