我的代码如下
- HTML code
<div id="demo" style="width: 500px; height: 300px;"> </div>
- JScript code
$(document).ready(function() { var coords = '38.871008,-77.055979'; var container = $("#demo"); var map = new google.maps.Map(container, { zoom: 12, // Close zoom! mapTypeId: google.maps.MapTypeId.ROADMAP // Use the classic roadmap }); var coordsarr = coords.split(','); var latlong = new google.maps.LatLng(parseFloat(coordsarr[0]), parseFloat(coordsarr[1])); var marker = new google.maps.Marker({ position: latlong, map: map }); map.setCenter(latlong); });
错误信息是
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://maps.gstatic.com/intl/zh_cn/mapfiles/api-3/7/12/main.js :: Ol :: line 60" data: no]
------解决方案--------------------
var container = $("#demo");
container 是jquery对象吧,google的构造函数怎么能传jquery对象呢。。。。
var map = new google.maps.Map(‘demo’, {
zoom: 12, // Close zoom!
mapTypeId: google.maps.MapTypeId.ROADMAP // Use the classic roadmap
});