0
我目前正在升級到Google Maps Geolocation API的「新」HTML5版本,並且出現了一些問題。該功能在我的電腦上完美運行,但不能在我的手機上使用Safari瀏覽器。代碼如下:Google地圖HTML5無法在我的手機上工作(Safari瀏覽器)
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var speed = position.coords.altitude;
var coords = new google.maps.LatLng(latitude, longitude);
alert(position.coords.speed);
var mapOptions = {
zoom: 15,
center: coords,
mapTypeControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(
document.getElementById('weather-map'), mapOptions
);
var marker = new google.maps.Marker({
position: coords,
map: map
});
});
} else {
alert('Geolocation API stöds inte i din webbläsare');
}
如果我if(navigator.geolocation) {
後立即設置alert()
和我的手機上更新的頁面,提醒窗口會出現,但如果我移動alert()
並設置navigator.geolocation.getCurrentPosition(...
後,它不會顯示。我已經測試過,如果瀏覽器能夠使用這個API並且它是。
我該如何解決這個問題?
在此先感謝。