すでに数日間デバッグを試みているという深刻な問題があります。ユーザーに現在の緯度と経度を取得し、それらを変数に格納するスクリプトがあります。ただし、この関数の外部で// initマップゾーンでこれらの変数を使用しようとすると、マップが表示されません。変数を警告することにより、位置関数の外側で変数が「未定義」に設定されていることがわかります。これが私のコードです:
//main function here
function initialize() {
var lat;
var lon;
//check if user has geo feature
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(
//get position
function(position){
lat = position.coords.latitude;
lon = position.coords.longitude;
},
// if there was an error
function(error){
alert('ouch');
});
}
//case the users browser doesn't support geolocations
else {
alert("Your browser doesn't support geolocations, please consider downloading Google Chrome");
}
//init map
var myOptions = {
center: new google.maps.LatLng(lat, lon),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
助けてくれてありがとう、アリエル