การค้นหา Latitude และ Longitude ด้วย HTML5

<!doctype html>
<html><head><title>Sample HTML5</title></head>
<body>
<p id=”location”>Current Location</p>
<button onclick=”getLocation()”>Get</button>
<script type=”text/javascript”>
var p1=document.getElementById(“location”);

function getLocation()
{
if (navigator.geolocation)
{   navigator.geolocation.getCurrentPosition(showPosition); }
else
{   p1.innerHTML=”Location not Support!!!”; }
}

function showPosition(position)
{   p1.innerHTML=”Lat : ” + position.coords.latitude+”<br/>lon:”+position.coords.longitude; }

function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENINED: p1.innerHTML=”Permission Denied”; break;
case error.TIMEOUT: p1.innerHTML=”TimeOut”; break;
case error.POSITION_UNAVAILABLE: p1.innerHTML=”No Position”; break;
case error.UNKNOW_ERROR: p1.innerHTML=”Unknown”; break;
}
}

</script></body></html>

—————————————————————————

RESULT


Scroll to Top