繁体   English   中英

Google Maps v3:未显示地图

[英]Google Maps v3: Map is not showing

您能在[Google Maps API]中解决此问题吗? 我不知道为什么地图没有显示。

这是小提琴。

使用Javascript:

 //Map Options var roadmap = { infoWindow: new google.maps.InfoWindow(), options: { map: { center: new google.maps.LatLng(34.02238, -118.293338), zoom: 15, mapTypeId: 'roadmap' }, marker: { position: roadmap.options.center, title: "Hello", icon: 'http://maps.google.com/mapfiles/ms/micons/blue-dot.png', shadow: 'http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png' } } }; //Street view Options var StreetView = { options: { position: roadmap.options.map.center, zoom: 1 } }; //Functions function bindInfoWindow(marker, map, infoWindow, html) { google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(html); infoWindow.open(map, marker); infoWindow.getContent(); marker.openInfoWindowTabsHtml(infoTabs); }); } function googleMaps() { //Road map roadmap.map = new google.maps.Map(document.getElementById("map"), roadmap.options.map); //Road map's Marker roadmap.options.marker.map = roadmap.map; roadmap.marker = new google.maps.Marker(roadmap.options.marker); //Street view map StreetView.map = new google.maps.StreetViewPanorama(document.getElementById("map_StreetView"), StreetView.options); //Bind onClick to marker & infoWindow bindInfoWindow(roadmap.marker, roadmap.map, roadmap.infoWindow, roadmap.options.marker.title); } //end of load() /*Load | Call googleMaps after document is loaded*/ google.maps.event.addDomListener(window, 'load', function() { googleMaps(); //... (add more code here) }); 

HTML:

 <!-- START: Google Maps API --> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> <script type="text/javascript" src="this_map.js"></script> <!-- __END: Google Maps API --> <div id="map-container" > <div id="map_StreetView" style="width: 350px; height: 250px"></div><br/> <div id="map" style="width: 350px; height: 250px"></div> </div> 
任何帮助,将不胜感激。

错误在这里:

position: roadmap.options.center

您不能引用您刚刚创建的对象。

我将其更改为:

position: new google.maps.LatLng( 34.02238, -118.293338 )

而且有效。

这是您的工作提琴: http : //jsfiddle.net/sGHqa/

TypeError: 'undefined' is not an object (evaluating 'roadmap.options') roadmap.options TypeError: 'undefined' is not an object (evaluating 'roadmap.options') ,因为您正在定义路线图,所以这是一种期望...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM