Google Maps API v3 Geolocation을 사용하여 사용자의 실제 위치를 얻습니다.Google Maps API v3 Google 크롬에서 Geolocation이 작동하지 않습니다.
여기
내 코드 (Google지도 예제의 코드와 동일) : 이것은 구글 크롬 &에 파이어 폭스에서 아니지만 꽤 잘 작동
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see a blank space instead of the map, this
// is probably because you have denied permission for location sharing.
var map;
function initialize() {
var mapOptions = {
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
// Try HTML5 geolocation
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
content: 'Location found using HTML5.'
});
map.setCenter(pos);
}, function() {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(60, 105),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="container">
<div class="entry-content">
<div class="blogtitle">IT</div><p> </p></td><td> </td><td><p> </p></td></tr></tbody></table><p> </p>
<div id="map-canvas"></div><!-- map-canvas end -->
</div><!-- entry-content end -->
</div><!-- container end -->
</body>
나는이 구글 개발자의 게시물을 발견 원정 여행. Chrome & Safari는 웹킷 브라우저이므로 생각합니다. 그러나 나는 그것을 고치는 법을 모른다.
누군가 나를 도울 수 있습니까?
그것의 어떤 비트를 작동하지 않습니다를 찾을 수 있습니다
? 지도가 표시되지 않고 사용자의 위치를 알 수 없으며 자바 스크립트 오류가 발생합니다. – duncan
오류가 발생했습니다 : '오류 : Geolocation 서비스가 실패했습니다 .' 그리고 마커는 러시아 어딘가의 숲에 있습니다 (스위스에 있습니다 ...) – Tyler