เทคโนโลยีด้านการระบุตำแหน่งของผู้ส่งข้อมูล (ใช้ Geolocation API )
- by Nat
ขอ blog จากเอกสารบางส่วนที่ส่ง NSC ไปหน่อย เผื่อมีประโยชน์กับท่านอื่นด้วย
ว่าด้วยเรื่องของการดึงข้อมูลพิกัดผ่านทาง Browser (ดึงพิกัดออกมาจากมือถือนั่นแล)
การดึงพิกัดจากมือถือ ทำได้โยการใช้ Geolocation 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';
}
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 การทำ geocoding
function codeAddress() {
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
- » Learning to use CSS and DIV Tags for Columns in Dreamweaver
- Investment information including spread betting.
- Business Practices » Local SEO
- Woods Recruiting › Bay Area local scoreboard for May 9
- The Stanford Review » 2010 Elections A Step in the Right Direction
- PGCYD Approves 2010 Endorsement Plan @ Prince Georges County Young …
- Noynoy did not inherit Tita Cory's Facebook fans – NOYPIPOL: The …
- HTML Pro Series Tutorial – #1 Working With DIV & Setting Up | HTML …
- Advance band div coding video 2 | geeksonsteroids.us
- a centre-left nation needs what kind of government? | afoe | A …
- Household Activities » Blog Archive » Power One Size 312 Zinc Air …
- Matthew Yglesias » The Left and Economics
- Feng Shui Compass – Finding Your Home's Precise Direction …
- Cheers to a Beautiful Mother's Day | The Tasteful Life
- Chicago politicos ''suiciding' right and left…' | RedState
- peHUB » VCs Privately Seethe Over Facebook's New Direction: “No …
- Left Creates New Class of Victims, Illegal Aliens, While Real …
- How To Get Over Somebody You Love | My Flirting Secrets
- VE Day, Moscow Style : Lawyers, Guns & Money
- Pac Div – Rollin' :: h.e.r.
เรื่องที่เกี่ยวข้อง