我想要創建一個Javascript對象,我們將其命名爲'geoloc'並將其放置在我創建的Javascript庫中。創建Javascript對象來保存用戶的地理位置座標
這個對象將使用HTML5地理位置API將用戶的位置的position.coords.latitude
和position.coords.longitude
值存儲爲兩個對象的屬性,讓我們命名他們geoloc.latitude
和geoloc.longitude
。
那麼我可以用他們我的html代碼裏面是這樣的:
<script type="text/javascript">
document.writeln('Your latitude is: ', geoloc.latitude);
document.writeln('Your longitude is: ', geoloc.longitude);
</script>
我已經嘗試過:
<a href="http://html5doctor.com/finding-your-position-with-geolocation">this</a>
,但它顯示一個警告;我需要將對象變量返回給我的html代碼。
在此先感謝
它顯示什麼樣的警示呢?這是地理位置權限確認嗎?如果是這樣,你無法避免它 - 用戶必須允許用戶代理查詢他們的位置。 – 2012-03-16 13:44:29