Friday 15 January 2010

javascript - Google map InfoWindow showing all address in the array rather than 1 -


I have a Google map and in my InfoWindow this information window is displaying all the addresses when I Transferring the php variable of the foreach array, it shows only the last item in the array. ? Addresses instead of MARKER_1 ect

Updated code now pulls inside MARKER_0 (: I missed the array refinement or missed it right inside the infoWindow function

here for my support The code is A, b, c, d).

  & lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {// Let's take a loan and type var lat = []; var lon = []; var type = []; var address = [], var restaurant = 'http: // Bar = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld = one | FF0000 | 000000 '; var x = 0; // Create a global table for the map on the looping map of the store index; // to create a map; and set it to zero; markerArray = [] value at zero Infowindow on the shop marker; php foreach ($ line as LatLong); // marker info // show To make the looping infowindow to get value from the database using php & lt for the field? & Gt; lat.push (& lt; php echo $ line? ['Late'] ;; & gt;); lon Push (& lt ;? php echo $ row ['long'];> & gt;; type.push (& lt ;? php echo $ line ['type'];? & Gt;); address.push "& Lt; php echo $ line ['address'];?>"); X ++; ; From function initialize () {// set center map var myOptions = {Zoom: 10, center: new google.maps.LatLng (lat [0], loan [0]), map a new map map = new google.maps.Map (document.getElementById google.maps.MapTypeId.ROADMAP} // Create: TypeControl: True, mapTypeControlOptions: {Shell : Google.maps.MapTypeControlStyle.DROPDOWN_MENU}, navigationControl: True, mapTypeId ( "map"), myOptions); // Define value and size infowindow infowindow = new google.maps.InfoWindow ({Size: new google.maps.size (150, 50)}); // Add marker in map // Set number of elements from the database based on the number of markers (var i = 0; i ;); Infowindow.open (map, marker, marker.address); }; Window.onload = initialize; }); & Lt; / Script & gt;   

And in the MyWrite section, the output in the firebug is output like this, so I know it's pulling up the right information!

// To get value using the database looping Php

  lat peash (lat); Lon.push (lng); Type.push (restaurant); Address.push ('a'); X ++; Lat.push (lat); Lon.push (lng); Type.push (bar); Address.push ("b"); X ++; Lat.push (lat); Lon.push (lng); Type.push (restaurant); Address.push ('c'); X ++; Lat.push (lat); Lon.push (lng); Type.push (bar); Address.push ('d'); X ++;   

Any help would be greatly appreciated.

You have 4 arguments in your make-up function:

  createMarker ( New google.maps.LatLng (lat [i], lon [i]), type [i], address [i], 'marker _' + i);   

But then you only use 3 of them,

  create a function marker (latlng, type, id) { < / Pre> 

> The function should not be announced:

  Create a marker (Letleng, Type, Address, Id) and then you can add this address to your marker A property for:  
  var marker = new google.maps.marker ({status: latlng, map: map, icon: type, id: id, address: address});   

which you can refer to then:

  var markerclick = function (latlng) {var marker = this; Var latLng = marker. GetPosition (); Infowindow.setContent ('& lt; h3 & gt; Marker is addressed: & lt; / h3 & gt;' + marker.address + ';); Infowindow.open (map, marker, marker.address); };    

No comments:

Post a Comment