У меня есть этот базовый c код для получения широты и долготы с помощью API геолокации:
showmap. html
<button onclick="getLocation()">Find me </button>
<script type="text/javascript" src="js/geolocation.js"></script>
js /geolocation.js
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
alert("Geolocation is not supported by your browser. Please update your browser. Visit Help Center.");
}
}
function showPosition(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
console.log("Latitude : " + latitude + "<br> Longitude :" + longitude);
}
Когда я нажимаю на кнопку, я получаю эту ошибку в консоли
SyntaxError: An invalid or illegal string was specified showmap.html:72
_sendMessage file:///home/user/Desktop/Projects/showmap.html:72
call file:///home/user/Desktop/Projects/showmap.html:64
getCurrentPosition file:///home/user/Desktop/Projects/showmap.html:16
getLocation file:///home/user/Desktop/Projects/js/geolocation.js:4
onclick file:///home/user/Desktop/Projects/showmap.html:1
fireMouseEvent resource://devtools/server/actors/emulation/touch-simulator.js:290
dispatchMouseEvents resource://devtools/server/actors/emulation/touch-simulator.js:264
Я пытаюсь выяснить, как решить Эта проблема. Разве это не работает, потому что я в file://
?