0
をマーカーをプロットするが、それはサメ頭をお読みください:地図ボックスあなたは、マーカーは、母なる地球ビールのラベル見ることができます以下のスクリーンショットでは間違った場所に
私のマップボックスマーカーをされて追加するための私のコード:
var lat;
var lng;
var markers = [];
var markerTemp;
for (i = 0; i < data.length; i++) {
lat = parseFloat(data[i].lat);
lng = parseFloat(data[i].lng);
if (lat == "" || lng == "") {
} else {
L.marker([lat, lng]).addTo(map).bindPopup(data[i].brewery);
markerTemp = L.marker([lat, lng]);
markers.push(markerTemp);
alert("Brewery: " + data[i].brewery + "Lat: " + lat + "Long: " + lng);
}
var group = L.featureGroup(markers);
map.fitBounds(group.getBounds());
}
変数データを以下に解析されているJSONである:
[{"brewery":"East Coast Beer Company","lat":"40.091779","lng":"-74.049265","breweryID":"0BRjKa"},{"brewery":"Ballast Point Brewing Company","lat":"32.766785","lng":"-117.195246","breweryID":"1d90Lc"},{"brewery":"Fulton Brewing Company","lat":"44.9849423","lng":"-93.2790206","breweryID":"5GoGSi"},{"brewery":"Stone Brewing Co.","lat":"33.115682","lng":"-117.119552","breweryID":"709vEK"},{"brewery":"The Lost Abbey","lat":"33.141417","lng":"-117.150076","breweryID":"9x7wNn"},{"brewery":"Dogfish Head Craft Brewery","lat":"38.770622","lng":"-75.310893","breweryID":"g0jHqt"},{"brewery":"Latitude 33 Brewing Co.","lat":"33.1362843","lng":"-117.2244859","breweryID":"GpPbOw"},{"brewery":"Coronado Brewing Company","lat":"32.6977264","lng":"-117.1731838","breweryID":"gVynTw"},{"brewery":"Iron Fist Brewing Company","lat":"33.145823","lng":"-117.238546","breweryID":"hjb9rn"},{"brewery":"Heritage Brewing","lat":"38.7523173","lng":"-77.4887259","breweryID":"LWv6MU"},{"brewery":"Karl Strauss Brewing Company","lat":"32.832461","lng":"-117.2318045","breweryID":"mtUjck"},{"brewery":"Bagby Beer Company","lat":"33.189225","lng":"-117.374257","breweryID":"Nl2U0R"},{"brewery":"Mother Earth Brew Company","lat":"38.770622","lng":"-75.310893","breweryID":"NwFxny"},{"brewery":"Pizza Port Brewing Company","lat":"33.1596505","lng":"-117.3478111","breweryID":"QSVVxD"},{"brewery":"Burley Oak Craft Brewery","lat":"38.3338561","lng":"-75.2169099","breweryID":"rKXfsB"},{"brewery":"Belching Beaver Brewery","lat":"33.1450383","lng":"-117.2285575","breweryID":"rVzPCl"},{"brewery":"San Marcos Brewery & Grill","lat":"33.134539","lng":"-117.190813","breweryID":"SEibYT"},{"brewery":"Union Craft Brewing Company","lat":"39.331938","lng":"-76.641971","breweryID":"t6Gyij"},{"brewery":"Rinn Duin Brewing","lat":"40.123373","lng":"-74.24754","breweryID":"T90yOZ"},{"brewery":"Victory Brewing Company","lat":"40.0061038","lng":"-75.6941546","breweryID":"VoKbnS"},{"brewery":"Heavy Seas","lat":"39.230827","lng":"-76.6751309","breweryID":"wTFQaf"},{"brewery":"Booze Brothers Brewing Co.","lat":"33.148172","lng":"-117.218047","breweryID":"xaBLno"},{"brewery":"Kane Brewing","lat":"40.2368095","lng":"-74.0442545","breweryID":"XqWTM7"},{"brewery":"AleSmith Brewing Company","lat":"32.892034","lng":"-117.144379","breweryID":"ygAzC9"},{"brewery":"Bay City Brewing","lat":"32.7579949","lng":"-117.2118382","breweryID":"yOH4Du"}]
あなたは私が右の値が、私は正しいデータがアラートを経て一つ一つに行くとに比較して検証
markerTemp = L.marker([lat, lng]);
markers.push(markerTemp);
に行っていたことを確認するために、このalert("Brewery: " + data[i].brewery + "Lat: " + lat + "Long: " + lng);
を追加見ることができるコードでは10
JSONの出力すべての外観が正しいと私は立ち往生して、目の第二のセットが大きく評価されます。ありがとう!
おかげで、それらを移動しました。私の質問で言及している問題は解決していません。 – Mike
こんにちはMike、私はあなたの質問の先頭に書いた2つの場所がJSONファイルの座標と全く同じであることに気付きました。したがって、他のものの上に1つを見ることは全く正常です。一方、私はコードで別の間違いを見つけ、私の答えに変更されたバージョンを追加しました。 –
コードヒントをお寄せいただきありがとうございました。同じlatとlngを見て、私の間違いがどこにあったのか分かりました。 – Mike