javascript를 사용하여 geolocation을 사용하는 방법을 배우려고합니다. 그러나 스크립트는 내가 생각한대로 작동하지 않습니다.내 코드에서 Geolocation이 작동하지 않습니다.
<!doctype html>
<html>
<title> Testing Geolocation</title>
<head>
<script>
function displayLocation(){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var div = document.getElementById("myLocation");
div.innerHTML =" You are at Latitude "+latitude+" and longitude "+longitude);}
window.onload = getMyLocation;}
function getMyLocation{
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(displayLocation);}
else{
alert("Oops! Geolocation function not supported");}
</script>
</head>
<body>
<div id="myLocation">
Your location will go here.
</div>
</body>
</html>
안녕, 오타를 수정 한 후, 스크립트가 여전히 작동하지 않습니다 : 다음은 내 코드입니다. 위도와 경도가 표시되지 않습니다.
내 생각을 예외없이'navigator.gelocation' 철자가 잘못되어'navigator.geolocation'이어야합니다. –
또한이 포스트가 설명하는 것처럼 http://stackoverflow.com/questions/3397585/navigator-geolocation-getcurrentposition-sometimes-works-sometimes-doesnt에서'getMyLocation()'전에'displayLocation' 함수를 정의하십시오. –
안녕하세요, 오타를 수정 한 후 스크립트가 여전히 작동하지 않습니다. 위도와 경도가 표시되지 않습니다. – user2106416