-1
사용자의 현재 위치가 표시된지도를 표시하고 싶습니다. HTML-5를 사용하여 본문로드에서 위도와 경도를 얻으려고하고 있으며 경도와 위도가 표시된지도를 표시하려고합니다. 여기 내 index.html을 내가 잘못하고 있어요현재 위치를 얻고지도에 표시하는 방법은 무엇입니까?
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
//x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
/*x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
*/
console.log(position.coords.latitude);
console.log(position.coords.longitude);
}
function loadMap() {
var mapOptions = {
center: new google.maps.LatLng(22.719840899999998, 75.8824308),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("sample"), mapOptions);
console.log(map);
}
<!DOCTYPE html>
<html>
<head>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD7lHDyDsOHYmd0tUrdbKKWpPlDkoDibik"></script>
<script type="text/javascript" src="index.js"></script>
</head>
<body onload="getLocation()">
<div id="sample" style="width:570px; height:580px;"></div>
<button onclick="loadMap()">Show Map</button>
</body>
</html>
입니까? 도와주세요.
그리고 문제는 무엇입니까? 'showPosition'이 호출되지 않았습니까? 콘솔에 오류가 있습니까? – Andreas