Javascript error with Google Maps API
I've created a simple static HTML page using the Google Maps API v3. This works fine in some browsers (IE v8 on Windows XP) but I'm having trouble getting it to load in the latest versions of Safari on Mac OS X 10.6.8 and Windows XP. I get these errors when I turn the Safari developer console on:
TypeError: 'undefined' is not a constructor (evaluating 'new google.maps.Size(150,50)')
TypeError: 'undefined' is not a constructor (evaluating 'new google.maps.LatLng(-30.2965590,153.1152650)')
I've put a copy of the file online at:
http://dl.dropbox.com/u/34923164/Errors_GoogleMaps.htm
Here's the html contents as well:
<html>
<head>
<meta nam开发者_Go百科e="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>Google Maps Sample</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var map = null;
function initialize() {
var myOptions = {
zoom: 13,
center: new google.maps.LatLng(-30.2965590,153.1152650),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
var point = new google.maps.LatLng(-30.2965590,153.1152650);
var icon = 'http://www.google.com/intl/en_us/mapfiles/ms/icons/blue-dot.png';
var marker = createMarker(point,'Location: 33 Harbour Drive Coffs Harbour', icon)
var point = new google.maps.LatLng(-30.2864430,153.1360230);
var icon = 'http://www.google.com/intl/en_us/mapfiles/ms/icons/red-dot.png';
var marker = createMarker(point,'Person: Fred Flinstone (108 Park Beach Road Coffs Harbour)')
var point = new google.maps.LatLng(-30.2941737,153.1156785);
var icon = 'http://www.google.com/intl/en_us/mapfiles/ms/icons/red-dot.png';
var marker = createMarker(point,'Person: Barney Rubble (108 Grafton St Coffs Harbour)')
}
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
function createMarker(latlng, html, icon) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
icon: icon,
map: map,
zIndex: Math.round(latlng.lat()*-100000)<<5
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>
i've tried your code posted on dropbox and didn't see any error using Safari 5.1 (Lion) and Chrome 12.0.742 maybe you have something wrong in cache or your network has some problem and it didn't download javascript code from google correctly
my 2 cents
精彩评论