// <![CDATA[ function getGeoLocation() { //Check if browser supports W3C Geolocation API if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); } else { alert('It seems like Geolocation, which is required for this page, is not enabled in your browser. Please use a browser which supports it.'); } } function successFunction(position) { var lat = position.coords.latitude; var lon = position.coords.longitude; //alert('Your latitude is :'+ lat +' and longitude is '+ lon); var latitudeDiv = document.getElementById("latitude"); var longitudeDiv = document.getElementById("longitude"); var gmap = document.getElementById("gmap"); var latlon = lat + "," + lon; latitudeDiv .innerHTML = lat; longitudeDiv.innerHTML = lon; //gmap.src = "http://maps.google.com.tw/maps?f=q&source=s_q&hl=zh-TW&geocode=&q=" + latlon + "&aq=&sll=" + latlon + "ie=UTF8&t=m&z=14&ll=" + latlon + "&output=embed"; //gmap.src = "http://maps.google.com.tw/maps?f=q&source=s_q&hl=zh-TW&geocode=&q=" + latlon + "&aq=&sll=" + latlon + "ie=UTF8&t=m&z=14&ll=" + latlon + "&output=embed"; gmap.src = "http://maps.google.com.tw/maps?q=" + latlon + "&output=embed"; } function errorFunction(position) { alert('Error!'); } // ]]> 經度: 緯度:
你好可以請問一下 你那個Geolocation 的按鈕式怎麼做的嗎??
您好~ 現在的 HTML5 瀏覽器大多有支援 geolocation 的功能: navigator.geolocation.getCurrentPosition(successFunction, errorFunction) 我那個按鈕按下去之後其實是去呼叫上列那個方法,然後在成功取得座標後連到 google map,將座標傳進去,你可以看這一頁的原始碼就能知道是怎麼做的了,程式大約是從本頁原始碼的第 264 ~ 304 行之間