1

我正在尝试将我的 google api v2 移植到 v3,但它不起作用....我收到“未定义折线”错误...:/旧的折线是 GPolyline,新的折线是新的 google.maps.Polyline

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

}
4

1 回答 1

1

Polyline确实没有定义。你在这里使用它:

encodedPolyline = Polyline.fromEncoded({

版本 3 不包括fromEncoded()- 看来您需要使用该geometry库(需要单独显式加载)和

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

[为清楚起见,在此处拆分为单独的行]

于 2012-06-04T12:32:14.440 回答