I am running the following code, and in the IE console I'm getting "stack overflow at line 26". Anyone know what I may be doing wrong here? I'm perplexed.
<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=utf-8">
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0
, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script src="
http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></s
cript>
<script src="
http://maps.googleapis.com/maps/api/js?sensor=false&v=3&libraries=geometry" type="text/javascript"></s
cript>
<script>
$(document).ready(function
(){
var latlngs = [];
var startingPoint;
var locations = ['1850 n. damen, chicago, il','1050 w. division, chicago, il', 'w cortland st and n damen ave, chicago, il', 'wicker park, n damen ave, chicago, il'];
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address
': 'USA'}, function (results, status) {
map.fitBounds(results[0].g
eometry.vi
ewport);
});
var bounds = new google.maps.LatLngBounds()
;
for (var j = 0; j < locations.length; j++) {
codeAddress(locations[j]);
}
startingPoint = new google.maps.LatLng(getLatL
ong('565 W. Adams, Chicago, IL 60661'));
var mapOptions = {
zoom: 14,
center: startingPoint,
mapTypeId: google.maps.MapTypeId.ROAD
MAP
}
var map = new google.maps.Map(document.g
etElementB
yId('map-c
anvas'), mapOptions);
var marker = new google.maps.Marker({
map: map,
icon: "
http://www.conceptfire-uk.com/wp-content/uploads/2011/07/icon-pin-color.png",
position: startingPoint
});
function codeAddress(address) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus
.OK) {
var location = results[0].geometry.locati
on;
compareDistances(location)
;
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
function getLatLong(address)
{
var geocoder = new google.maps.Geocoder();
var result = "";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus
.OK) {
result = results[0].geometry.locati
on;
alert(result);
} else {
result = "Unable to find address: " + status;
}
});
console.log("TEST" + address + " " + result);
}
function compareDistances(loc){
latlngs.push(loc);//add markers to the latlngs array
//when the markers array length matches the locations array length...
if (latlngs.length == locations.length){
var distances = [];
//use geometry.spherical to calculate the distances between pairs of lat/lng coordinates
for(var j = 0; j < latlngs.length; j++){
distances.push({distance:g
oogle.maps
.geometry.
spherical.
computeDis
tanceBetwe
en(startin
gPoint, latlngs[j]), marker: j});
}
//reorder the distances, shortest first, closest will then be distances[0] and distances[1]
distances.sort(function(a,
b) {
return a.distance - b.distance;
});
//add the two closest markers
var marker1 = new google.maps.Marker({map: map, position: latlngs[distances[0].marke
r]});
var marker2 = new google.maps.Marker({map: map, position: latlngs[distances[1].marke
r]});
//extend the bounds of the map to include the two closest markers and the starting point
bounds.extend(startingPoin
t);
bounds.extend(latlngs[dist
ances[0].m
arker]);
bounds.extend(latlngs[dist
ances[1].m
arker]);
//zoom the map to nicely fit the bounds of the two closest markers and the starting point
map.fitBounds(bounds);
}
}
});
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
ASKER