Level 2
Jul 19, 2018
2
Level 2
get geo location with vue
hi how i found the latitude and longitude of the user with the browser gps from computer and mobile with vue? but auto (if the gps are open)
thanks
Level 47
You can use the HTML Geolocation API
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function (position) {
//do work work here
/*
$.post("url-here", {
long: position.coords.longitude,
lat: position.coords.latitude
}).done(function (response) {
alert(responsse)
});
*/
},
function (error) {
alert(error.message);
}, {
enableHighAccuracy: true
, timeout: 5000
}
);
} else {
alert("Geolocation is not supported by this browser.");
}
in this snippet from on of my projects, we check first if the Geolocation API is supported
if (navigator.geolocation).
the we get the position navigator.geolocation.getCurrentPosition(calback) and pass it as a variable to a call back.
the position will be passed as an object which have the following properties
position.coords.longitude;
position.coords.latitude;
3 likes
Please or to participate in this conversation.