Q:

Undefined is not a function in Google Maps API

I'm building an class to render maps using the Google Maps API.
This is my class
function Map() {
}

Map.prototype.map = null;
Map.prototype.map_options = null;
Map.prototype.div_map = null;
Map.prototype.directions_service = null;
Map.prototype.center = null;
Map.prototype.points = null;

Map.prototype.start = function() {

    this.map_options = {
        zoom: 14,
        center: this.center,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        streetViewControl: false
    };

    this.map = new google.maps.Map(document.getElementById(this.div_map), this.map_options);

    this.directions_service = new google.maps.DirectionsRenderer();

    this.directions_service.setOptions({
        preserveViewport: true,
        suppressInfoWindows: true,
        polylineOptions: {
            strokeWeight: 2,
            strokeOpacity: 0.8,
            strokeColor: "blue"
        }
    });

    this.map.setMap(this.directions_service);
};

When I use this class, a received an error, in this line:
this.map.setMap(this.directions_service);

The error is: Uncaught Typeerror: undefined is not a function
But, I test the this.map variable with typeof(), and returns 'object'.
The this.div_map is set normally, also, the initial map in rendered.
I'm doing something wrong?

A:

Object map has no method 'setMap'. But DirectionRenderer has. You have to change that line to
this.directions_service.setMap(this.map)

