简体   繁体   English

使用Checkbox的Google Maps Waypoints

[英]Google Maps Waypoints using Checkboxes

Can anyone tell me how to convert the following code to work using checkboxes instead.. 谁能告诉我如何将以下代码转换为可使用复选框运行。

var checkboxArray = document.getElementById("waypoints");
for (var i = 0; i < checkboxArray.length; i++) {
  if (checkboxArray.options[i].checked == true) {
    waypts.push({
        location:checkboxArray[i].value,
        stopover:true});

I have a number of checkboxes on the page with different values in them and I would like the user to click the points they would like to add to their route. 我在页面上有许多复选框,其中有不同的值,我希望用户单击要添加到路线的点。

Help!! 救命!!

Cheers 干杯

Justin 贾斯汀

This is the sample code from google documentation for google map version 3 which plots waypoints between already set start and end locations. 这是来自Google文档的Google地图版本3的示例代码,该代码在已设置的开始和结束位置之间绘制航点。 and here is the answer. 这是答案。

assume that you have checkboxes like the following 假设您有以下复选框

<input type='checkbox' name='waypoints[]' value='someplace1'>
<input type='checkbox' name='waypoints[]' value='someplace2'>
<input type='checkbox' name='waypoints[]' value='someplace3'>
<input type='checkbox' name='waypoints[]' value='someplace4'>
<input type='checkbox' name='waypoints[]' value='someplace5'>

and then the following code will work for you. 然后以下代码将适合您。

var checkboxArray = document.getElementsByName("waypoints[]");
for (var i = 0; i < checkboxArray.length; i++) {
  if (checkboxArray[i].checked == true) {
    waypts.push({
        location:checkboxArray[i].value,
        stopover:true});

But if the user clicks the checkbox in random order then .... it is left to you to decide. 但是,如果用户以随机顺序单击该复选框,那么......由您决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM