Scarnet
Scarnet

Reputation: 500

Using Traffic Layer In Google Maps API

I'm trying to use the traffic layer in the google maps API however when I try to initialize the TrafficLayer object using this line

 var trafficLayer = new google.maps.TrafficLayer();

firebug throws this exception message for me

TypeError: ({oa:null}) is not a constructor

here's where I include the API

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>

and here's where I initialize the map

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); 
}

Upvotes: 0

Views: 780

Answers (1)

Scarnet
Scarnet

Reputation: 500

Okay I found it apparently unlike the other google maps API services I need to use an app key for that one

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&key={My Key}&sensor=false&libraries=places"></script>

Upvotes: 1

Related Questions