geolocation을 사용하여 현재 위치의 위도와 경도를 얻으려고합니다. 최근까지도 매우 유사한 코드가 작동했으며 왜 작동이 멈췄는지 알 수 없습니다. 더 이상 변수 위도 또는 경도을 설정하지 않습니다. js 코드를 살펴볼 때 getCurrentPosition() 메서드는 건너 뛰고 이유는 확실하지 않습니다. 기이하게도 getCurrentPosition() 메서드에 경고 상자를 추가하면 위도와 경도가 올바르게 표시되고 표시됩니다 ... 왜 그런지 알지 못합니다.navigator.geolocation.getCurrentPosition()가 작동하지 않습니다.
var gl;
try {
if (typeof navigator.geolocation === 'undefined'){
gl = google.gears.factory.create('beta.geolocation');
} else {
gl = navigator.geolocation;
}
} catch(e) {}
var latitude;
var longitude;
if (gl) {
gl.getCurrentPosition(
function (position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
//alert("got the lat & long - lat=" + latitude + ", lng=" + longitude);
},
function (error) {
alert("Error getting geolocation:" + error);
}
);
} else {
alert("Geolocation services are not supported by your web browser.");
}
그런 다음 Google Maps API를 사용하여지도에 일부 마커를 설정하십시오.
, 당신에게피터을 주셔서 감사
편집 여기
이상한 행동을 보여 JSFiddle의 코드 :
코드를 정확하게 들여 씁니다. 우리가 따라하기 쉽고 잠재적 인 문제를 더 쉽게 발견 할 수 있도록 도와줍니다. – jsalonen
죄송합니다. 지금은 더 좋았을 것입니다 (엉망인 함수 이름 일뿐입니다). – stank345
JS에서'alert()'이후에 뭔가가 작동하는 경우, 어딘가에 경쟁 조건이 있음을 알게됩니다. 함수가 건너 뛰었습니까? 당신은 "넘어서"오히려 넘어서 "들어갔습니까"? –