微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Typeahead js事件将标记添加到传单地图上的搜索位置

如何解决使用Typeahead js事件将标记添加到传单地图上的搜索位置

我正在尝试创建一个搜索栏,该标记标记添加到传单地图中要搜索的位置。我想要的是:

  1. 用户搜索某个位置并按下搜索按钮时,该位置的坐标上应出现一个标记
  2. 这些位置不是通用的。这意味着它们不是像加拿大,北京等受欢迎的地区。它们是我在我的大学中使用typeahead.js手动添加搜索栏中的位置。代码如下:
var substringMatcher = function(strs) {
  return function findMatches(q,cb) {
    var matches,substringRegex;

    // an array that will be populated with substring matches
    matches = [];

    // regex used to determine if a string contains the substring `q`
    substrRegex = new RegExp(q,'i');

    // iterate through the pool of strings and for any string that
    // contains the substring `q`,add it to the `matches` array
    $.each(strs,function(i,str) {
      if (substrRegex.test(str)) {
        matches.push(str);
      }
    });

    cb(matches);
  };
};

var places = ['Dean Office','HOD Space Sciences','HOD Mechanical Engineering','HOD Electrical Engineering','HOD Materials Science and Engineering','HOD Maths','HOD Aerospace Engineering','Vice Chancellor Office','Department of Avionics and Aerospace','Department of Electrical Engineering','Department of Materials Science and Engineering','Transport Office','Student Affairs'
];

$('#the-basics .typeahead').typeahead({
  hint: true,highlight: true,minLength: 1
},{
  name: 'places',source: substringMatcher(places)
});

我不知道如何使用预先选择的选项将标记添加到地图,并且对JS函数和事件不是很好。有人可以在用户搜索栏中选择他/她的选项并单击搜索按钮之后,建议如何将标记添加到地图上吗?

P.S。我试过了,但是没用:

$('#the-basics .typeahead').on('typeahead:selected',function(evt,item) {
    var pulsingIcon = L.icon.pulse({iconSize:[10,10],color:'red'});
    var search = L.marker([33.521500,73.176870],{icon: pulsingIcon});
    if (places == 'Dean Office') {
        search.setLatLng([33.521500,73.176870])
    }
    else (places == 'HOD Space Sciences') {
        search.setLatLng([33.519560,73.176355])
    }  
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?