Better "near me" feature

This commit is contained in:
echarp 2019-05-14 22:57:32 +02:00
parent 803b4858be
commit 49d9f83c2b

View File

@ -1,16 +1,17 @@
$(document).on 'turbolinks:load', ->
$('.digest .filter').each ->
return unless navigator.geolocation
$('.digest .filter:first-child').each ->
$(this).before '
<a id="nearMe" href="#">
<a id="nearMe" href="#" title="">
<em class="fa fa-2x fa-street-view"></em>
</a>'
$('#nearMe').click (event) ->
event.preventDefault()
nearMe()
nearMe = ->
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition showPosition
navigator.geolocation.getCurrentPosition showPosition, (error) ->
switch error.code
when error.PERMISSION_DENIED
$('#nearMe').remove()
showPosition = (position) ->
coords = "[#{position.coords.latitude}, #{position.coords.longitude}]"