Jquery hỏi truy cập vị trí
$(window).on("load", function() { if ('geolocation' in navigator) { navigator.geolocation.getCurrentPosition(function(position) { lat = position.coords.latitude; long = position.coords.longitude; }, function(error) { switch (error.code) { case error.PERMISSION_DENIED: console.log("User denied the request for Geolocation."); break; case error.POSITION_UNAVAILABLE: console.log("Location information is unavailable."); break; case error.TIMEOUT: console.log("The request to get user location timed out."); break; case error.UNKNOWN_ERROR: console.log("An unknown error occurred."); break; } } ) } else { console.log("Geolocation is not supported by this browser."); } });
Đoạn code trên đây liên quan đến hỏi vị trí người dùng với latitude và longitude