การระบุพิกัดด้วย HTML5

การระบุพิกัด latitude/longitude ด้วย HTML5 สามารถทำได้โดยการใช้ navigator.geolocation
แต่ความแม่นยำขึ้นอยู่กับอุปกรณ์ที่ใช้เปิดเว็บไซต์ เช่น เปิดจาก PC (ไม่มี GPS) หรือเปิดจากโทรศัพท์มือถืออย่าง Android และ iPhone จะมี GPS ทำให้ระบุพิกัดได้อย่างแม่นยำ

[code lang=”html”]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ทดสอบ geolocation</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
ตำแหน่งของฉัน:
<div id="geo_data"></div>
<script type="text/javascript">
if ( navigator.geolocation ) {
// ตรงนี้คือรองรับ geolocation
navigator.geolocation.getCurrentPosition(function(location) {
var location = location.coords;
$("#geo_data").html(‘lat: ‘+location.latitude+'<br />long: ‘+location.longitude+'<br /> altitude: ‘+location.altitude+'<br /> accuracy: ‘+location.accuracy+'<br /> altitude accuracy: ‘+location.altitudeAccuracy+'<br /> heading: ‘+location.heading+'<br /> speed: ‘+location.speed);
}, function() {
alert(‘มีปัญหาในการตรวจหาตำแหน่ง’);
});
} else {
alert(‘เบราเซอร์นี้ไม่รองรับ geolocation’);
}
</script>
</body>
</html>
[/code]

ค่าที่ได้จากการเรียกใช้ navigator.geolocation ไม่ได้มีแค่ latitude/longitude ค่าอื่นๆสามารถดูได้ที่ http://dev.w3.org/

ตัวอย่าง : geolocation_html5

ที่มา : http://www.okvee.net/