javascript - 谷歌地图 API v3 - TypeError : Result of expression 'google.maps.LatLng' [undefined] is not a constructor

标签 javascript google-maps-api-3

我正在创建一个静态 html 页面来显示数据中的多个位置。我刚刚复制了其中一个示例并正在向后工作,但我在 Safari 检查器中收到以下错误:

main.js:1SyntaxError: Parse error
sample.htm:10TypeError: Result of expression 'google.maps.LatLng' [undefined] is not a constructor.

这是我的 html 代码:

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Multi Markers Sample via Google Maps</title> 
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
function initialize() {
var myLatlng = new google.maps.LatLng(-30.2965590,153.1152650);
var myLatlng1 = new google.maps.LatLng(-30.2956470,153.1123707);
var myLatlng2 = new google.maps.LatLng(-30.2864430,153.1360230);
var myOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: 'http://www.google.com/intl/en_us/mapfiles/ms/icons/blue-dot.png',
title:"Original Location"     });   
var marker = new google.maps.Marker({
position: myLatlng1,
map: map,
title:"Tom Cruise"     }); 
var marker = new google.maps.Marker({
position: myLatlng2,
map: map,
title:"Lady Gaga"     }); 
} 
</script> 
</head> 
<body onLoad="initialize()">   
<div id="map_canvas"></div> 
</body> 
</html>

我不确定我在这里做错了什么 - 它实际上适用于 Windows 上的 IE v8 但不适用于 Safari,我需要让它同时适用于两者。

最佳答案

为您的谷歌地图请求添加回调函数。 它会在 Google 加载所需的一切后执行。

http://maps.google.com/maps/api/js?sensor=false&callback=initialize

关于javascript - 谷歌地图 API v3 - TypeError : Result of expression 'google.maps.LatLng' [undefined] is not a constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6577404/

相关文章:

javascript - 文本中的动画,从右到左隐藏文本已安装

javascript - 动态更改 Google MAP v3 中的 map 类型

javascript - 获取矩形内的地点谷歌地图

javascript - 我可以使用 insertAdjacentHTML 插入 DOM 元素吗

javascript - 在javascript中下拉子菜单

javascript - 来自 webapp 的 Facebook 分享对话框深度链接

javascript - 重新利用 map 标记进行加权热图

javascript - 谷歌地图 - 多边形编辑 - 标记顶点

google-maps - 谷歌java map API - 热图太微弱

javascript - 结合图片上传ajax和表单提交ajax