Thanks for replies.
2STU, I don't think its the problem of the format as I tried not only
generate by php, but just manualy write in html after <script> var
cities = [...

2Larry. Well there is no geocoding as I give lat and lng coordinates
to the markers. Can't give you the link as its tested locally.

The array that I collect via php works and returns value inside the
code. Actually almost all variable are coming to js file from external
php. Arrays prices, roomss etc. are also collected in php and they
perfectly work withing gmap.js and only array cities doesn't want to
work. If I uncomment //var cities = [... in the code below -
everything works perfectly...

gmap.js is included in header of html and variables and arrays are
created already in body but before <div> with map.
Here is the code of gmap.js file

(function() {
  window.onload = function() {
        // Creating a reference to the mapDiv
    var mapDiv = document.getElementById('map');

    // Creating a latLng for the center of the map
    var latlng = new google.maps.LatLng(latc, lngc);

    // Creating an object literal containing the properties
    // we want to pass to the map
    var options = {
      center: latlng,
      zoom: zoomvar,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
          scaleControl: true,
          scaleControlOptions: {
        position: google.maps.ControlPosition.BOTTOM
    },
          mapTypeControl: true,
          mapTypeControlOptions: {

          style: google.maps.MapTypeControlStyle.DROPDOWN_MENU

          }
    };

 // Creating the map
    var map = new google.maps.Map(document.getElementById('map'),
options);
// Creating a LatLngBounds object
        var bounds = new google.maps.LatLngBounds();
        // Creating a variable that will hold
    // the InfoWindow object
    var infowindow;
// Initializing MarkerManager
        var mgr = new MarkerManager(map);
        var dotss = [];

//add markers from array places []
// Looping through the places array
    for (var i = 0; i < places.length; i++) {

      // Adding the markers
      var marker = new google.maps.Marker({
        position: places[i],
        //map: map,
                icon: markerurl,
        title: 'Place number ' + i
      });
dotss.push(marker);
// Wrapping the event listener inside an anonymous function
 // that we immediately invoke and passes the variable i to.
      (function(i, marker) {

// Creating the event listener. It now has access to the values of
// i and marker as they were during its creation
        google.maps.event.addListener(marker, 'click', function() {

// Check to see if we already have an InfoWindow
          if (!infowindow) {
            infowindow = new google.maps.InfoWindow();
          }
// Creating the content
      var content = '<div id="info">' +
                '<table> <tr><td>' +
                '<img src=' + markerurl + ' width=75 hights=75 align=left> </
td><td><b>' + streets[i] + '<b><br>' +
        '<b>' + prices[i] + '</b> <br>' +
        '<b>Êîìíàòû</b>' + roomss[i] + '<br>' +
        '<p><a href="#">Ïîäðîáíåå</a></p>' +
        '</td></tr></table></div>';
          // Setting the content of the InfoWindow
          infowindow.setContent(content);

// Tying the InfoWindow to the marker
          infowindow.open(map, marker);

        });

      })(i, marker);


// Extending the bounds object with each LatLng
      bounds.extend(places[i]);



         }
//finished adding markers from array places []


// Creating a marker that represents Kiev
        var kiev = new google.maps.Marker({
        position: new google.maps.LatLng(50.4531, 30.5447),
        icon: 'http://google-maps-icons.googlecode.com/files/hotel.png'
        });
// Adding a click event to the Kiev  marker
        google.maps.event.addListener(kiev, 'click', function() {
// Setting the zoom level of the map to 10
        map.setZoom(10);
// Setting the center of the map to the clicked markers position

        map.setCenter(kiev.getPosition());


        });

// Creating a marker that represents Odessa
        var odessa = new google.maps.Marker({
        position: new google.maps.LatLng(46.5171, 30.7356),
        icon: 'http://google-maps-icons.googlecode.com/files/hotel.png'
        });
// Adding a click event to the Odessa  marker
        google.maps.event.addListener(odessa, 'click', function() {
// Setting the zoom level of the map to 10
        map.setZoom(10);
// Setting the center of the map to the clicked markers position
        map.setCenter(odessa.getPosition());
        });

        // Creating a marker that represents Donetsk
        var donetsk = new google.maps.Marker({
        position: new google.maps.LatLng(48.0134, 37.8060),
        icon: 'http://google-maps-icons.googlecode.com/files/hotel.png'
        });
// Adding a click event to the Donetsk  marker
        google.maps.event.addListener(donetsk, 'click', function() {
// Setting the zoom level of the map to 10
        map.setZoom(10);
// Setting the center of the map to the clicked markers position
        map.setCenter(donetsk.getPosition());
        });

// Creating a marker that represents Kharkov
        var kharkov = new google.maps.Marker({
        position: new google.maps.LatLng(49.9592, 36.2157),
        icon: 'http://google-maps-icons.googlecode.com/files/hotel.png',
        title: 'places.length'
        });
// Adding a click event to the Kharkov  marker
        google.maps.event.addListener(kharkov, 'click', function() {
// Setting the zoom level of the map to 10
        map.setZoom(10);
// Setting the center of the map to the clicked markers position
        map.setCenter(kharkov.getPosition());
        alert (places.length);
        });

// Creating a marker that represents Dnepropetrovsk
        var dnepropetrovsk = new google.maps.Marker({
        position: new google.maps.LatLng(48.4615, 34.9825),
        icon: 'http://google-maps-icons.googlecode.com/files/hotel.png'
        });
// Adding a click event to the Dnepropetrovsk  marker
        google.maps.event.addListener(dnepropetrovsk, 'click', function() {
// Setting the zoom level of the map to 10
        map.setZoom(10);
// Setting the center of the map to the clicked markers position
        map.setCenter(dnepropetrovsk.getPosition());
        });

// Creating a marker that represents Zaporozhye
        var zaporozhye = new google.maps.Marker({
        position: new google.maps.LatLng(47.8450, 35.1665),
        icon: 'http://google-maps-icons.googlecode.com/files/hotel.png'
        });
// Adding a click event to the Zaporozhye  marker
        google.maps.event.addListener(zaporozhye, 'click', function() {
// Setting the zoom level of the map to 10
        map.setZoom(10);
// Setting the center of the map to the clicked markers position
        map.setCenter(zaporozhye.getPosition());
        });

// Creating a marker that represents Lvov
        var lvov = new google.maps.Marker({
        position: new google.maps.LatLng(49.8541, 24.0161),
        icon: 'http://google-maps-icons.googlecode.com/files/hotel.png'
        });
// Adding a click event to the Lvov  marker
        google.maps.event.addListener(lvov, 'click', function() {
// Setting the zoom level of the map to 10
        map.setZoom(10);
// Setting the center of the map to the clicked markers position
        map.setCenter(lvov.getPosition());
        });

// Creating an array that will contain the markers Kyiv and Odesa

var cities = [];
        for (var i = 0; i < citiesphp.length; i++) {
        cities.push(citiesphp[i]);

 }
//var cities = [kiev, odessa, donetsk, kharkov, dnepropetrovsk,
zaporozhye, lvov];





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


// Adjusting the map to new bounding box
    map.fitBounds(bounds)

  };

})();

Thanks!

On 9 Грд, 09:32, stu <[email protected]> wrote:
> Hi
> I'm not sure exactly what you're doing with the data, but it sounds
> like your main problem is getting a php/msql array into a format that
> javascript can use - is that right?
> If so, the trick is to look into using JSON. Do a search on php data
> to javascript and you will find examples, but the basic way is to use
> json_encode to convert the php array into JSON. Then pickup the JSON
> encoded variable in your javascript and convert to a javascript JSON
> object. You can parse JSON with JSON.parse if the browser supports it,
> or use something like jquery which has a JSON parser.
> Hope that is what you wanted.
> ...stu
>
> On Dec 9, 5:25 am, Futsutsuka <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi there,
>
> > need you help.
> > I have a blog .
> > I have a gmap.js file that creates a google map with markermanager
> > code inside. And I have a markermanager_packed.js from google
> > library.
> > Both are included in html file index.php generated by php.
> > Each post in blog has a variable with city name that is collected to
> > an array $cities.
> > the code in gmap.js 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();
> >         });
>
> > My php code in html generates and array
>
> > <script>
> > var cities = [kiev, odessa, donetsk, kharkov, dnepropetrovsk,
> > zaporozhye, lvov];
> > </script>
>
> > but the js code does not recognize it and does not create markers.
> > If I write same array inside of gmap.js - everything works perfectly.
>
> > Thank you in advance for your help.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to