Google Maps API v3 - TypeError:表达式结果'google.maps.LatLng'[undefined]不是构造函数 [英] Google Maps API v3 - TypeError: Result of expression 'google.maps.LatLng' [undefined] is not a constructor

查看:120
本文介绍了Google Maps API v3 - TypeError:表达式结果'google.maps.LatLng'[undefined]不是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个静态html页面来显示数据中的多个位置。我刚刚复制了其中一个示例,但后退了,但在Safari Inspector中出现以下错误:

main.js:1SyntaxError:解析错误
sample.htm:10TypeError:表达式结果'google.maps.LatLng'[undefined]不是构造函数。

这是我的html代码:

 <!DOCTYPE html> 
< html>
< head>
< meta name =viewportcontent =initial-scale = 1.0,user-scalable = no/>
< meta http-equiv =content-typecontent =text / html; charset = UTF-8/>
< title>多标记通过Google地图示例< / title>
< link href =http://code.google.com/apis/maps/documentation/javascript/examples/default.css =stylesheettype =text / css/>
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>< / script>
< script type =text / javascript>
函数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地图请求添加回调函数。
它会在Google加载所需内容后执行。

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


I'm creating a static html page to display a number of locations from a data. I've just copied one of the samples and are working backwards but I'm getting the following error in the Safari Inspector:

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

Here's my html code:

<!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>

I'm not sure what I'm doing wrong here - it actually works in IE v8 on Windows but not in Safari and I need to get it working for both.

解决方案

Add callback function to your google maps request. It'll be executed after Google loads everything it needs.

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

这篇关于Google Maps API v3 - TypeError:表达式结果'google.maps.LatLng'[undefined]不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆