0
マーカーのIDとそれぞれの緯度と経度を含むgeoJSONファイルがあります。 (下記のJSONを参照してください)。ファイルから動的変数を作成
私は$getJSON
を使用してそのプロパティにアクセスしています。
geoJSONファイルは常に変化します(マーカーの追加または削除)。だから私がしたいのは、各マーカーをループして、ファイルに含まれる変数の数を作成してから、Clickイベントリスナーを各変数に設定することです。
次のように私が何かをしたいと思います。ここでは
$.getJSON("MyFile.geojson",
function(JSON_Result) {
var JSON_Features_Count = JSON_Result['features'].length;
for (i=0; i<JSON_Features_Count; i++){
var coordinates = JSON_Result['features'][i]['geometry']['coordinates']; //Lat = coordinates[1]; Long = coordinates[0]
var Marker_i = // this variable should be dynamic, because I don't know the number of markers my file has.
new google.maps.Marker({
position: new google.maps.LatLng(coordinates[1],coordinates[0]),
map: map,
});
}
});
は私のJSONファイルの例です:私はこの方法を行うことを好む
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "ID": 1}, "geometry": { "type": "Point", "coordinates": [ -43.256001299999895, -18.966999944999898] } },
{ "type": "Feature", "properties": { "ID": 2}, "geometry": { "type": "Point", "coordinates": [ -43.3659564559999, -18.733241581 ] } },
]
}