<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="HTTP://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var initialLocation;
var taipei = new google.maps.LatLng(25.09108, 121.5598);
var browserSupportFlag = new Boolean();

 

function initialize() {
var myOptions = {
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

 

Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
}
Browser doesn't support Geolocation
else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}

 

function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
alert("地圖定位失敗");
} else {
alert("您的瀏覽器不支援定位服務");
}
initialLocation = taipei;
map.setCenter(initialLocation);
}
}
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:1024px; height:768px"></div>
</body>
</html>

 

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()