在html网页上添加bingmap javascript错误

时间:2011-02-10 13:21:06

标签: javascript html bing-maps bing-api

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript"  src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

<script type="text/javascript">
function GetMap()
{ 

  var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), 
   {credentials: "Your Bing Maps Key",
   center: new Microsoft.Maps.Location(45.5, -122.5),
   mapTypeId: Microsoft.Maps.MapTypeId.road,
    zoom: 7});
 }
 </script>
 </head>
<body onload="GetMap();">
 <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>  
</body>
  </html>

我甚至试过加载一个简单的地图,但是我在Microsoft类未定义的

上得到了一个js错误

2 个答案:

答案 0 :(得分:3)

将以下行添加到&lt; head&gt;页面的一部分,在您粘贴的部分之前:

<script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0" type="text/javascript"
charset="UTF-8"></script>

答案 1 :(得分:1)

您是否包含了地图api的附件?

<script type="text/javascript" src="bingmaps.js"></script>

或者您正在使用其他服务,在这种情况下,您需要在AJAX调用中指定服务的位置...

http://www.earthware.co.uk/blog/index.php/2010/10/using-jquery-with-the-bing-maps-rest-api/