1

Google API v2 を v3 に移植しようとしていますが、機能しません....「ポリラインが定義されていません」というエラーが表示されます... :/ 古いポリラインは GPolyline で、新しいポリラインは新しい google.maps.Polyline です

https://developers.google.com/maps/documentation/javascript/overlays?hl=de-DE#ポリライン

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 に答える