Skip to content
Permalink
Browse files

Suggest nearby lat/lon search for search queries

  • Loading branch information
simonw committed Dec 29, 2019
1 parent cd3e70a commit dae47b94029e0f47b01c0aa48374ee5f325c08f5
Showing with 18 additions and 0 deletions.
  1. +18 −0 templates/query-browse-search.html
@@ -51,6 +51,24 @@ <h3 class="title is-3">{{ rows.__len__() }} result{% if rows.__len__() != 1 %}s{
{% include "_museum_card.html" %}
{% endfor %}
</section>
<script>
document.addEventListener('DOMContentLoaded', () => {
let input = document.getElementsByName("q")[0];
let q = input.value;
if (q) {
let geocodeUrl = `https://nominatim.openstreetmap.org/search?format=jsonv2&q=${encodeURIComponent(q)}`;
fetch(geocodeUrl).then(r => r.json()).then(o => {
let displayName = o[0].display_name;
let latitude = parseFloat(o[0].lat);
let longitude = parseFloat(o[0].lon);
let p = document.createElement('p');
p.style.marginTop = '1em';
p.innerHTML = `Or <a href="/?latitude=${latitude.toFixed(3)}&longitude=${longitude.toFixed(3)}">view museums near ${displayName}</a>`;
input.parentNode.parentNode.parentNode.appendChild(p);
});
}
});
</script>
</body>

</html>

0 comments on commit dae47b9

Please sign in to comment.
You can’t perform that action at this time.