我尝试使用google maps API中的流量图层,但是当我尝试使用此行初始化TrafficLayer对象时
var trafficLayer = new google.maps.TrafficLayer();
firebug为我抛出此异常消息
TypeError:({oa:null})不是构造函数
这里我包含了API
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
以及我在这里初始化地图
function InitialRouteMapLoad(mapId,fromLon,fromLat,toLon,toLat) {
var fromlatlng = new google.maps.LatLng(fromLat, fromLon, true);
var tolatlng = new google.maps.LatLng(toLat, toLon, true);
bounds = new google.maps.LatLngBounds();
bounds.extend(fromlatlng);
bounds.extend(tolatlng);
var myOptions =
{
zoom: 12,
center: bounds.getCenter(),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(mapId), myOptions);
bounds = new google.maps.LatLngBounds();
google.maps.event.addListener(map, 'click', function(e) {
});
geocoder = new google.maps.Geocoder();
ser = new google.maps.DirectionsService();
ren = new google.maps.DirectionsRenderer({ 'draggable': true });
ren.setMap(map);
debugger;
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}
答案 0 :(得分:1)
好的,我找到了 显然不同于其他谷歌地图API服务,我需要使用一个应用程序密钥
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&key={My Key}&sensor=false&libraries=places"></script>