Google MapsのJavaScript APIのgoogle.maps.Polylineクラスから何らかの異常な動作が発生しています。解決済み - google.maps.Polyline(JavaScript API) "path"プロパティが初期化されない
私が達成しようとしているのは、連続的に更新されたLatLngLiteralの配列からマップにポリラインを描画することです。
問題 - google.maps.Polylineの "path"プロパティが初期化されず、であり、したがってポリラインは表示されません。マップがロードされた後、のgoogle.maps.Polylineの初期化に「パス」プロパティを含めるという事実に関係なく、そのようなプロパティは存在しません。(ポリラインオブジェクトが作成され、他のプロパティにアクセスできるそれの)。
正確なエラーが表示されます。「ok(map.js:74)」で未定義のプロパティ 'push'を読み取ることができません。私はsetPath()メソッドを使って "path"の値を設定しようとしましたが、LatLngクラスを使ってみました。MVCArrayクラスを試しました。あなたの助けを前にありがとう!コードは以下の通りです。 (以下のコードが最適化されていない、私はちょうどこのプロジェクトのための基本的な機能に始めている)
function loadMap(){
var options = {
zoom : 15,
center : {lat:42.553080288955805, lng: 11.25}
};
map = new google.maps.Map(document.getElementById("test-map"),options);
player = new google.maps.Marker(
{
map: map,
position: {lat:42.553080288955805, lng: 11.25},
title: "This is you!",
label: {
text: "You are here!",
color: "rgb(50,50,255)",
fontFamily: "Helvetica, sans-serif",
fontWeight: "bold"
}
});
//initializing path variable
pathArray = [
new google.maps.LatLng(-42, 11),
new google.maps.LatLng(-43, 12),
new google.maps.LatLng(-44, 15)
];
playerPath = new google.maps.Polyline({
map: map,
path: pathArray, //the value here is not assigned for some reason
strokeColor: "orange", //this property and value is assigned and
//accessible after the map was loaded
visible: true
});
}
let options2 = {
enableHighAccuracy : true,
timeout : 10000,
maximumAge : 30000
};
var positionWatcher = navigator.geolocation.watchPosition(ok,null,options2);
function ok(p){
player.setPosition({lat:p.coords.latitude, lng:p.coords.longitude}); // works ok
playerPath.path.push({lat:p.coords.latitude, lng:p.coords.longitude});
//above line provides the mentioned error
}
確かに、問題はないが、見てください。 –