次の問題コードがさらに下にあります。私がこれをしているとき
city[i] = response[i].name;
私が持っているすべての都市のすべての名前を印刷できます。しかし、次のコードも保存したいので、多次元配列が必要です
L.marker([response[i].lat, response[i].lon]).bindPopup(response[i].name);
そして、多次元配列に保存できると思ったので、例として
city[1]["CityName"] = "New York"
city[1]["Locations"] = L.marker([location]).bindPopup(name);
それで、今私が電話city[1]['Locations']
すると、L.Markerを取得しますよね?
これが私のコードです
function init()
{
region = 'all';
var url = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
attribution = "(c) OSM contributors, ODBL";
var minimal = L.tileLayer(url, {styleID: 22677, attribution: attribution});
$.ajax
({
type: 'GET',
url: 'webservice.php',
data: {region: region},
success: function(response, textStatus, XMLHttpRequest)
{
var city = new Array();
var lygStr = '';
for(var i = 0; i < response.length; i++)
{
//alert(response[i].lat + " | " + response[i].lon + " | " + response[i].name);
alert(response[i].name);
city[i]["CityName"] = response[i].name;
//L.marker([response[i].lat, response[i].lon]).bindPopup(response[i].name);
if(i + 1 == response.length)
{
lygStr += city[i]["CityName"];
}
else
{
lygStr += city[i]["CityName"] + ", ";
}
}
alert("Test" + lygStr);
var cities = L.layerGroup([lygStr]);
map = L.map("map1",
{
center: new L.Latlng(resposne[1].lat, response[0].lon),
zoom: 10,
layers: [minimal, cities]
});
}
});
}