Google지도 자바 스크립트 API 및 HTML5 geolocation에 약간 이상한 문제가 있습니다.Google지도 자바 스크립트 API + HTML5 geolocation 기발한
나는 다음과 같은 실행 온로드가 : 이제
var geocoder;
var map;
var latlng;
function initialize() {
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
latlng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
});
}else{
latlng = new google.maps.LatLng(geoip_latitude(),geoip_longitude());
}
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 8,
center: latlng,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
var latLong = String(event.latLng).replace('(', '');
latLong = latLong.replace(')', '');
$('#latlng').attr('value', latLong);
});
function placeMarker(location) {
if(undefined != initialize.marker){
initialize.marker.setMap(null);
}
initialize.marker = new google.maps.Marker({
position: location,
map: map
});
initialize.marker.setMap(map);
map.setCenter(location);
}
}
, 브라우저가 위치 정보를 지원하는 경우이 이이며, 위도 + 긴 얻을지도를 작성하고 중심으로지도를 표시해야 할 일을 위도 + 경도.
내가 geoip_ 기능 (maxmind)를 사용하지만 위치 정보가 이상한 문제가있는 경우 그것은 잘 작동:
코드가 같이 실행되는 경우를, 구글지도 표시가없는 회색 상자로 표시됩니다 지도 및 컨트롤 없음.
경고를 추가하는 경우(); 직후에
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
latlng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
});
}else{
latlng = new google.maps.LatLng(geoip_latitude(),geoip_longitude());
}
지도가 잘 표시됩니다.
그게 뭐야?