首页 > 解决方案 > 在传单 OSM 上的附近搜索

问题描述

有人可以帮我在传单上搜索附近吗?目前我只有地理编码搜索,我希望当我搜索一个地方时,我可以在一个范围内看到附近的商店、医疗中心、餐馆等。

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"
    integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
    crossorigin=""/>
  <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"
    integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg=="
    crossorigin=""></script>

<!-- Load Esri Leaflet from CDN -->
  <script src="https://unpkg.com/esri-leaflet@2.2.4/dist/esri-leaflet.js"
    integrity="sha512-tyPum7h2h36X52O2gz+Pe8z/3l+Y9S1yEUscbVs5r5aEY5dFmP1WWRY/WLLElnFHa+k1JBQZSCDGwEAnm2IxAQ=="
    crossorigin=""></script>

<!-- Load Esri Leaflet Geocoder from CDN -->
  <link rel="stylesheet" href="https://unpkg.com/esri-leaflet-geocoder@2.2.14/dist/esri-leaflet-geocoder.css"
    integrity="sha512-v5YmWLm8KqAAmg5808pETiccEohtt8rPVMGQ1jA6jqkWVydV5Cuz3nJ9fQ7ittSxvuqsvI9RSGfVoKPaAJZ/AQ=="
    crossorigin="">
  <script src="https://unpkg.com/esri-leaflet-geocoder@2.2.14/dist/esri-leaflet-geocoder.js"
    integrity="sha512-uK5jVwR81KVTGe8KpJa1QIN4n60TsSV8+DPbL5wWlYQvb0/nYNgSOg9dZG6ViQhwx/gaMszuWllTemL+K+IXjg=="
    crossorigin=""></script>
       <style>
       #mapid{
           width: 100%;
           height: 400px;
       }
       </style>
<body>
  <div id="wrapper">
    <% include ../.././partials/nav.ejs %>
    <ul class="breadcrumb">
      <li><a href="#">Home</a></li>
      <li class="active">Dashboard</li>
    </ul>
    <div id="mapid"></div>
   <script>
   var mymap = L.map('mapid').setView([37.0902, -95.7129], 4);
   L.tileLayer('https://tiles.wmflabs.org/hikebike/{z}/{x}/{y}.png', {
    maxZoom: 19,
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);

  var searchControl = L.esri.Geocoding.geosearch().addTo(mymap);
  var results = L.layerGroup().addTo(mymap);

  searchControl.on('results', function(data){
  results.clearLayers();

  for(var i =data.results.length -1; i>=0; i--){
    results.addLayer(L.marker(data.results[i].latlng));
  }
})
  </script>

这是我目前拥有的代码行。

标签: javascripthtmlleaflet

解决方案


推荐阅读