纬度/长阵列作为谷歌地图上的标记(API V3) [英] Lat/Long Array as Markers on Google Maps (API V3)

查看:123
本文介绍了纬度/长阵列作为谷歌地图上的标记(API V3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Google地图上显示一组纬度/经度位置数组(使用v3 api)。我的代码如下 - 任何想法为什么它不工作? (控制台中没有错误)

  var locs = [51.38254,-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.78806,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 -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()方法需要2个参数。您只能传入一个。



Google LatLng API



创建一个多维数组:

var locs = [[51.38254,-2.362804],[51.235249,-2.297804],[51.086126,-2.210767]等。



,您可以这样做:



position:new google.maps.LatLng(locs [i ] [0],locs [i] [1]),


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.38254, -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]),

这篇关于纬度/长阵列作为谷歌地图上的标记(API V3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆