2014-04-30 2 views
0

Google Maps API를 사용하여지도를 렌더링하는 클래스를 작성하고 있습니다. 내가 테스트 Uncaught Typeerror: undefined is not a functionUndefined가 Google Maps API의 함수가 아닙니다.

그러나 :

this.map.setMap(this.directions_service); 

오류는 다음과 같습니다

내가이 클래스를 사용할 때,이 라인에서 오류가 발생

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

내 클래스 this.map 변수는 typeof()이며, 'object'을 반환합니다.

this.div_map도 정상적으로 설정되며 렌더링 된 초기지도도 설정됩니다.

내가 잘못하고있는 것이 있습니까?

답변

2

개체 맵에는 'setMap'메서드가 없습니다. 그러나 DirectionRenderer가 있습니다. 해당 줄을

this.directions_service.setMap(this.map) 
+0

으로 변경해야합니다. 고맙습니다. –

관련 문제