feature/geolocation implemented
This commit is contained in:
1 parent
6d91934229
commit
83be006a83
3 files changed
+39
No files matched your search
@@ -0,0 +1,24 @@
|
||||
function getLocation() {
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(success, error);
|
||||
}
|
||||
}
|
||||
|
||||
function success(position) {
|
||||
const { latitude, longitude } = position.coords;
|
||||
|
||||
fetch("api/location" , {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ latitude, longitude })
|
||||
}).then(res => res.json())
|
||||
.then(data => {
|
||||
console.log(data.results[0].formatted_address);
|
||||
})
|
||||
}
|
||||
|
||||
function error(err) {
|
||||
console.error("Geolocation error: ", err);
|
||||
}
|
||||
@@ -18,7 +18,12 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<button onclick="getLocation()" class="inline-flex justify-center hover:text-gray-900 items-center py-3 px-5 sm:ms-4 text-base font-medium text-center text-white rounded-lg border border-white hover:bg-gray-100 focus:ring-4 focus:ring-gray-400"></button>
|
||||
</section>
|
||||
|
||||
|
||||
</main>
|
||||
|
||||
<script src="/static/scripts/geolocation.js"></script>
|
||||
|
||||
<%- include("./partials/footer") %>
|
||||
Reference in new issue
Block a user