Loading...

HTML5 Geolocation

Temperature: 0 °C

ChungChung
author_tools

說真的,HTML5 Geolocation的功能真的好用...

輕鬆就可以讓網站也能取得目前所在的地理位置

這次把它運用在innstory裡也是為了方便未來寫下動態或是故事,必竟住址比較不是那麼容易記下...

索性就把這工作交給系統~

<script>
var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
}
</script>

上述function只是取得座標位置,若要將座標轉換成地址還得靠下列function
var geocoder = new google.maps.Geocoder();
                    geocoder.geocode({ location: new google.maps.LatLng(lat, lng) },
                    function (results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            document.getElementById("address_guest").value =results[0].formatted_address;
                            }}
                            );

Url link

昨晚已把這功能也加入了innstory。

台北市內湖區江南街71巷75弄 Go

https://innstory.com/story-HTML5_Geolocation-575
寫程式筆記

Prev
 那桌上其實已消逝的記憶

Next
多桑__李鴻欽漫畫 

Nearby Attractions

台北市內湖區江南街71巷75弄-Nearby Attractions

  • 大同之家(含網球場) Go
  • 國立臺灣大學日式宿舍─羅銅壁... Go
  • 新富市場 Go
  • 行政院 Go
  • 臺灣總督府交通局遞信部 Go
  • 圓山別莊 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

Android Studio 2.3 陽春型計算機進階版

Android Studio...

andrio5 將之前的陽春型計算機用了不怎麼聰明的方式改善了幾個地方。 首先,我將數字的宣告由in...

瀏覽器升級ie9後FCKEditor無法使用對話框解決方法

瀏覽器升級ie9後FCKEd...

原文網址:http://ecshop.tw/bbs/archiver/tid.html 升級到 IE...

利用 css 讓 ul 置中呈現

利用 css 讓 ul 置中...

以前寫網站...總是喜歡用Table 包住內容.. 而隨著時空的轉換...現在大都用div..或者....

Recommended reading

Other stories happened at this address

毛豆紅蘿蔔馬鈴薯炒肉片佐鄉愁

毛豆紅蘿蔔馬鈴薯炒肉片佐鄉愁...

毛豆加上紅蘿蔔切丁、馬鈴薯切丁炒上豬肉片。 嗯,這是我小時候熟悉的味道。我們家常煮~ 雖說Mandy...

原來種九層塔並不需要種子啊~

原來種九層塔並不需要種子啊~...

我真的很愛九層塔的香味~ 在台灣,從小吃鹹酥雞到家庭料理九層塔煎蛋都少不了這一味。 當然更別說是南洋...

數字是不是真的會說話?

數字是不是真的會說話?

以前,在寫下第個網站的那時,我其實非常迷戀數字。 每次看著計數器上數字的跳動,我知道那跳動的不只是數...

解決手機瀏覽器上點擊輸入框放大問題

解決手機瀏覽器上點擊輸入框放...

開發RWD的網站已經是趨勢,主要也是因為手機用戶實在是太多 但在過程中一直有個問題困擾著我.... ...

兒子開始發揮畢卡索的藝術天份,只是...在鞋墊上塗鴉是新的作品?

兒子開始發揮畢卡索的藝術天份...

兒子開始發揮畢卡索的藝術天份,只是...在鞋墊上塗鴉是新的作品?

Android Studio 2.3 隨機改變背景顏色

Android Studio...

class 開始學習APP 其實我照著工具書上的方式總是在宣告變數時會產生問題~ 例如工具書上寫著可...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format