Javascript URL中的纬度和经度坐标
我有一个纬度和经度坐标的列表,我想将下面URL字符串(显示在页面上)中的“+lat+”和“+long+”替换为相应的坐标作为随机选择 如何用javascript实现这一点 纬度/经度坐标:Javascript URL中的纬度和经度坐标,javascript,arrays,latitude-longitude,Javascript,Arrays,Latitude Longitude,我有一个纬度和经度坐标的列表,我想将下面URL字符串(显示在页面上)中的“+lat+”和“+long+”替换为相应的坐标作为随机选择 如何用javascript实现这一点 纬度/经度坐标: 42.14/72.65 42.00/71.26 53.21/45.27 62.56/65.25 URL示例: //testpage.com?纬度=“+lat+”&经度=“+long+” 期望输出的示例: //testpage.com?纬度=42.14,经度=72.65 将坐标存储在对象数组中,然后获取介于0和
将坐标存储在对象数组中,然后获取介于0和数组长度之间的随机位置
var coords = [{lat:42.14,lng:72.65},{lat:42.00,lng:71.26}];
var randomPos = Math.floor(Math.random() * coords.length);
var url = 'http://foo.com?lat='+coords[randomPos].lat+'&lng='+coords[randomPos].lng;
Math.floor((Math.random()*4)+1)代码>