Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see few problems.. You are missing <code>function</code> declaration for your <code>geocodeAddress(xmldata)</code> function.. so change line 14 as:</p> <pre><code>function geocodeAddress(xmldata) { ... other code continues here ... </code></pre> <p>Then it should work, I also noticed that you are not extending your <code>var bounds = new google.maps.LatLngBounds();</code> object when you are adding markers so remember to add your <code>createMarker</code> function to contain it, like this:</p> <pre><code> function createMarker(latlng, html) { var marker = new google.maps.Marker ({ map: map, position: latlng }); google.maps.event.addListener(marker, 'click', function() { info_window.setContent(html); info_window.open(map, marker); }); bounds.extend(latlng); // Here we tell what are next viewport bounds } </code></pre> <p>Tested, and everything works after that :) Cheers!</p> <p><strong>Edit:</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Google Maps Multiple Markers&lt;/title&gt; &lt;script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="scripts/downloadxml.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var map = null; var geocoder = new google.maps.Geocoder(); var info_window = new google.maps.InfoWindow(); var bounds = new google.maps.LatLngBounds(); function geocodeAddress(xmldata) { var address = xmldata.getElementsByTagName('address')[0].firstChild.data; var city = xmldata.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, status) { if (status == google.maps.GeocoderStatus.OK) { createMarker(results[0].geometry.location, info_text); } else { alert("geocode of "+ address +" failed:"+status); } }); } function createMarker(latlng, html) { var marker = new google.maps.Marker ({ map: map, position: latlng }); google.maps.event.addListener(marker, 'click', function() { info_window.setContent(html); info_window.open(map, marker); }); bounds.extend(latlng); // Here we tell what are next viewport bounds } 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 } map = new google.maps.Map(document.getElementById('map'), myOptions); google.maps.event.addListener (map, 'click', function () { info_window.close(); }); downloadUrl('listings.xml', function (listings_data) { listings_data = xmlParse(listings_data); var markers = listings_data.documentElement.getElementsByTagName('listing'); var geocoder = new google.maps.Geocoder(); for (var i = 0; i &lt; markers.length; i++) { geocodeAddress(markers[i]); } google.maps.event.addListenerOnce(map, 'idle', function() {map.fitBounds(bounds);}); }); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="initialize();"&gt; &lt;div id="map" style="width: 500px; height: 400px;"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Remember to create scripts folder where you place your downloadxml.js , since it is using path as: <code>&lt;script type="text/javascript" src="scripts/downloadxml.js"&gt;&lt;/script&gt;</code> Also dont forget to add <code>listings.xml</code></p> <p>So the files you need are organized as:</p> <pre><code>index.html scripts/downloadxml.js listings.xml </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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