Как я могу работать с Leoclet Control Geocode? - PullRequest
0 голосов
/ 08 апреля 2020

Я планирую добавить в свое приложение управляющий геокодер leaflet или окно поиска. Хотя я написал необходимый код, он не отображает геокодер, и я не знаю, что не так. Я предоставил часть моего index.html файла, включая соответствующий код.

<link rel="stylesheet" href="{% static 'geocoder/Control.Geocoder.css' %}" />
<script type="text/javascript" src="{% static 'geocoder/Control.Geocoder.js' %}"></script>

<script>
var geocoder = L.Control.geocoder().on('markgeocode', function(event) {
     var center = event.geocode.center;
     L.marker(center).addTo(map);
     map.setView(center, map.getZoom());
}).addTo(map);
</script>

1 Ответ

0 голосов
/ 09 апреля 2020

Вы должны установить геокод "тип": Типы

var _geocoderType = L.Control.Geocoder.nominatim();
var geocoder = L.Control.geocoder({
   geocoder: _geocoderType
}).addTo(map);

geocoder.on('markgeocode', function(event) {
     var center = event.geocode.center;
     L.marker(center).addTo(map);
     map.setView(center, map.getZoom());
});
...