Lat/Long Array as Markers on Google Maps (API V3)
I need to display an array of latitude/longitude locations as an array on Google Maps (using the v3 api). My code's below - any ideas why it's not working? (There are no errors in the console)
var locs = ["51.382开发者_开发问答54, -2.362804", "51.235249, -2.297804", "51.086126, -2.210767", "51.084519, -2.262813", "51.175994, -2.159207", "51.132978, -2.213939", "51.207289, -2.181474", "51.321724, -2.205518", "51.317219, -2.210649", "50.700816, -1.925721", "50.719979, -2.074488", "50.810063, -1.919034", "50.785094, -1.849725", "50.842648, -1.777575", "50.723047, -1.902297", "50.743044, -1.880132", "51.71355, 0.154967", "51.992676, 0.602668", "52.355964, -1.486877", "53.523356, -1.107254", "51.87591, -2.235986", "51.670729, -1.934476", "51.542953, -0.28102", "51.52132, 0.098986", "52.271354, 0.788806", "51.346031, -0.478255", "51.263343, -1.140235", "51.481736, -1.089953", "51.476566, -0.514911", "51.505462, -0.555614", "51.558631, -1.78224", "51.351101, -1.995069", "51.380722, -2.039105", "51.416719, -2.124294", "51.42063, -2.133049", "51.533076, -1.925663", "51.348518, -1.797868", "51.331682, -1.776469", "51.127299, -1.568594", "51.082304, -1.172732", "50.994651, -1.495699", "50.988355, -1.499401", "51.074562, -1.774168", "51.066228, -1.799655", "51.071929, -1.794634", "51.218585, -1.515494", "51.080011, -1.860008", "5151.070508, -1.810412", "51.056581, -1.795259", "51.043955, -1.789822", "51.20323, -1.906011", "51.229055, -1.951243", "51.061094, -1.998836", "51.039063, -1.999079", "51.067313, -2.070322", "51.099235, -1.787773", "51.250454, -1.764469", "51.006591, -1.650057", "50.999451, -2.080693", "50.993131, -2.246465", "51.006542, -2.197207", "51.01744, -2.186619", "51.042629, -2.272731", "51.007395, -2.332772", "55.605281, -2.899154", "53.395123, -2.537949", "53.684928, -1.511449"];
var marker, i;
for (i = 0; i < locs.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locs[i]),
map: map
});
}
google.maps.LatLng()
method takes 2 parameters. You are only passing in one.
Google LatLng API
Create a multidimesional array:
var locs = [ ["51.38254", "-2.362804"], ["51.235249", "-2.297804"], ["51.086126", "-2.210767"], etc.
and this will allow you to do:
position: new google.maps.LatLng(locs[i][0], locs[i][1]),
精彩评论