2012-06-04 101 views
1

我想將我的谷歌api v2移植到v3,但它不起作用....我得到「折線未定義」錯誤...:/舊的折線是GPolyline和新的是確實沒有定義谷歌地圖API v3端口

https://developers.google.com/maps/documentation/javascript/overlays?hl=de-DE#Polylines

var map = ""; 
var mapConfig = ""; 
var mapElements = ""; 
var curActiveMenuButton = ""; 
var clickHandlerElementCount = ""; 


//window.onload = function() { 
//window.addEvent('domready', function() { 
//document.addEvent('domready', function() { 
//alert("The DOM is ready."); 
//initializeMap(); 
//}); 

/* 
* function initializeMap() 
* 
* Initalisierung der Google-Map. 
*/ 
function initializeMap(){ 

     // Karte ins DOM einhängen 
     map = new google.maps.Map($('map_canvas'), myOptions); 

     //place the map on the canvas 
     //map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

     var latlng = new google.maps.LatLng(51.05758110879136, 10.451431274414062); 

     // default zoomlevel and center point 
     var myOptions = { 
      zoom: 12, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
      navigationControl: true, 
      mapTypeControl: true, 
      scaleControl: true, 
     }; 

     // default zoomlevel and center point 
     var encodedPolyline = new google.maps.Polyline(); 

     // find bounding polyline and recalculate map center 
     for (var i = 0; i < mapElements.length; i++) { 
      if (mapElements[i]['titel'] == "nationalparkhainich") { 
        encodedPolyline = Polyline.fromEncoded({ 
        points: mapElements[i]['pol'], 
        levels: mapElements[i]['lev'] 
       }); 
       mapCenter = encodedPolyline.getBounds().getCenter(); 
       i = mapElements.length; 
      } 
     } 


     // Kartenmenue initialisieren 
     //initializeMapMenue(); 

} 

回答

1

Polyline新google.maps.Polyline。在這裏您可以使用它:

encodedPolyline = Polyline.fromEncoded({

3版不包括fromEncoded() —看來,你需要使用geometry庫(這需要單獨明確加載)和

encodedPolyline.setPath(
    google.maps.geometry.encoding.decodePath(mapElements[i]['pol']) 
    ); 

[爲了清晰起見,在分開的線上分開]