Note that there are some explanatory texts on larger screens.

plurals
  1. POgoogle map info window multiple addresses via xml
    primarykey
    data
    text
    <p>I'm using the Google map code below to retrieve and plot markers for multiple addresses from an XML file dynamically created with PHP. The code is doing everything I need except for displaying the correct information in the Google map info window for the corresponding marker. I get the information of the last XML item/listing for all the markers.</p> <p>I've been searching and trying different variations to get it to work, but no luck.</p> <p>sample XML data</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;listings&gt; &lt;listing&gt; &lt;address&gt;123 Street&lt;/address&gt; &lt;city&gt;MANOTICK&lt;/city&gt; &lt;/listing&gt; &lt;listing&gt; &lt;address&gt;456 Street&lt;/address&gt; &lt;city&gt;MANOTICK&lt;/city&gt; &lt;/listing&gt; &lt;listing&gt; &lt;address&gt;111 Avenue&lt;/address&gt; &lt;city&gt;MANOTICK&lt;/city&gt; &lt;/listing&gt; &lt;listing&gt; &lt;address&gt;777 Avenue&lt;/address&gt; &lt;city&gt;Ottawa&lt;/city&gt; &lt;/listing&gt; &lt;listing&gt; &lt;address&gt;333 Street&lt;/address&gt; &lt;city&gt;Manotick&lt;/city&gt; &lt;/listing&gt; &lt;/listings&gt; </code></pre> <p>google map code</p> <pre><code>function initialize () { var myLatLng = new google.maps.LatLng(45.2340684, -75.6287287); var myOptions = { zoom: 10, mapTypeControl: true, center: myLatLng, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }, StreetViewControl: false, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('google_map'), myOptions); var info_window = new google.maps.InfoWindow; google.maps.event.addListener (map, 'click', function () { info_window.close(); }); downloadUrl ('listings.xml', function (listings_data) { var markers = listings_data.documentElement.getElementsByTagName('listing'); var geocoder = new google.maps.Geocoder(); for (var i = 0; i &lt; markers.length; i++) { var address = markers[i].getElementsByTagName('address')[0].firstChild.data; var city = markers[i].getElementsByTagName('city')[0].firstChild.data; var address_google_map = address + ', ' + city + ', ON'; var info_text = address + '&lt;br /&gt;' + city + ' ON'; geocoder.geocode ({'address': address_google_map}, function (results) { var marker = new google.maps.Marker ({ map: map, position: results[0].geometry.location }); google.maps.event.addListener (marker, 'click', function() { info_window.setContent(info_text); info_window.open(map, marker); }); }); } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload