Skip to content

Commit

Permalink
Suggest nearby lat/lon search for search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Dec 29, 2019
1 parent cd3e70a commit dae47b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions templates/query-browse-search.html
Expand Up @@ -51,6 +51,24 @@ <h3 class="title is-3">{{ rows.__len__() }} result{% if rows.__len__() != 1 %}s{
{% include "_museum_card.html" %} {% include "_museum_card.html" %}
{% endfor %} {% endfor %}
</section> </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> </body>


</html> </html>

0 comments on commit dae47b9

Please sign in to comment.