<script>
navigator.geolocation.getCurrentPosition(show_position);
//This function does the work of getting the actual user coordinates
function show_position(position){
var lat = position.coords.latitude;
var longi = position.coords.longitude;
var tick = position.timestamp;
document.getElementById("Coord1").innerHTML=lat;
document.getElementById("Coord2").innerHTML=longi;
}
</script>
<p>Your Latitude is: <b id="Coord1" style="color:blue;"> </b></p>
<p>Your Longitude is: <b id="Coord2" style="color:blue;"> </b> </p>
안녕 모두,. 그러나 navigator.geolocation.getCurrentPosition(show_position);
을 실행하는 javascript 버튼을 만들 수 있습니까? 검색 상자가 있고 그 옆에 버튼이 있어야하고 사용자가 클릭하면 자동으로 빈 상자를 채운 다음 검색합니다. 가능한지 아닌지는 알 수 없습니다. 당신은 클릭 이벤트자바 스크립트 HTML5 위치 버튼
x$("#btnInit").click(loadDemo);
//run the function
function loadDemo() {
navigator.geolocation.getCurrentPosition(show_position);
//This function does the work of getting the actual user coordinates
function show_position(position){
var lat = position.coords.latitude;
var longi = position.coords.longitude;
var tick = position.timestamp;
document.getElementById("Coord1").innerHTML=lat;
document.getElementById("Coord2").innerHTML=longi;
}
}
에 navigator.geolocation를 실행할 수