เทคโนโลยีด้านการระบุตำแหน่งของผู้ส่งข้อมูล (ใช้ Geolocation API )

 - by Nat

ขอ blog จากเอกสารบางส่วนที่ส่ง NSC ไปหน่อย เผื่อมีประโยชน์กับท่านอื่นด้วย

ว่าด้วยเรื่องของการดึงข้อมูลพิกัดผ่านทาง Browser  (ดึงพิกัดออกมาจากมือถือนั่นแล)

 

การดึงพิกัดจากมือถือ ทำได้โยการใช้ API   ซึ่งส่วนสำคัญที่ใช้ในโครงงานนี้คือ Coordinates interface

ซึ่งมีรายละเอียดดังนี้


  interface Coordinates {
    readonly attribute double latitude;
    readonly attribute double longitude;
    readonly attribute double? altitude;
    readonly attribute double accuracy;
    readonly attribute double? altitudeAccuracy;
    readonly attribute double? heading;
    readonly attribute double? speed;
  };

 

แอตทริบิวต์ latitude , longitude เป็นค่าตำแหน่งในภูมิศาสตร์เก็บอยู่ในรูปทศนิยม

แอตทริบิวต์  altitude เป็นค่าความสูงของตำแหน่ง
แอตทริบิวต์  accuracy และ altitudeAccuracy เป็นค่าความแม่นยำของพิกัด
แอตทริบิวต์ heading เป็นทิศทางของการเคลื่อนที่
แอตทริบิวต์ speed เป็นความเร็วของการเคลื่อนที่

โดยมีวิธีการเรียกใช้ได้ดังนี้ 

ตัวอย่างการ ดึงค่าพิกัด

 

เมื่อเรียกฟังก์ชั่น displayLocation จะได้ดังนี้

 
 
 

 
code ในส่วนของการ Detect Browser 
if (useragent.indexOf('Firefox') != -1) {
    browser = 'Firefox';
} else if (useragent.indexOf('iPhone') != -1) {
    browser = 'iPhone';
} else if (useragent.indexOf('Android') != -1) {
    browser = 'Android';
} else if (useragent.indexOf('Pre') != -1) {
    browser = 'Pre';
} else {
    browser = 'Unknown Browser';
จาก http://plebeosaur.us/etc/map/location.html
 
 

code การทำ  complex marker 
image['under'] = new google.maps.MarkerImage('/CTIS/markers/under/image.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(30, 30),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32));
 

code การทำ

  function codeAddress() {
    var = document.getElementById("").value;
    if (geocoder) {
 
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
 map.setZoom(12); 
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
  }

 

code การทำ reverse geocoding    
 function codeLatLng() {
   var input = "40.730885,-73.997383";
   var latlngStr = input.split(",",2);
   var lat = latlngStr[0];
   var lng = latlngStr[1];
var latlng = new google.maps.LatLng(lat, lng);
 
   if (geocoder) {
     geocoder.geocode({'latLng': latlng}, function(results, status) {
       if (status == google.maps.GeocoderStatus.OK) {
         if (results[1]) {
  // alert(results[1].formatted_address);
         } else {
           alert("No results found");
         }
       } else {
         alert("Geocoder failed due to: " + status);
       }
     });
   }
 }

จาก http://code.google.com/apis/maps/documentation/v3/examples/geocoding-reverse.html



By 

Related Blogs

เรื่องที่เกี่ยวข้อง