日期:2014-05-17  浏览次数:20736 次

HTML5瀛︿範绗旇(鍥?-Geolocation API

涓€銆佷綅缃俊鎭?/p>

1銆佹暟鎹?/p>

浣嶇疆淇℃伅鐢辩粡搴︺€佺含搴﹀潗鏍囧拰涓€浜涘叾浠栧厓鏁版嵁缁勬垚銆?/p>

绾害锛氳窛绂昏丹閬撲互鍖楁垨浠ュ崡鐨勬暟鍊笺€傛瘮濡傦細39.17222

缁忓害锛氳窛绂昏嫳鍥芥牸鏋楀▉娌讳互涓滄垨浠ヨタ鐨勬暟鍊笺€傛瘮濡傦細-120.13778

缁忕含搴﹀彲浠ヤ互鍗佽繘鍒惰〃绀猴紝涔熷彲浠ヤ互DMS锛堣搴︼級鏍煎紡琛ㄧず銆?/p>

HTML5 Geolocation API鐨勫潗鏍囨牸寮忔槸鍗佽繘鍒舵牸寮忋€?/p>

闄ょ粡绾害澶栵紝HTML5 Geolocation杩樻彁渚涘潗鏍囩殑鍑嗙‘搴︺€備緷鎹祻瑙堝櫒鎵€鍦ㄧ殑纭欢璁惧锛岃繕鍙兘鎻愪緵涓€浜涘厓鏁版嵁锛屽寘鎷捣鎷斻€佹捣鎷斿噯纭害銆佽椹舵柟鍚戝拰閫熷害绛夈€傚鏋滆繖浜涘厓鏁版嵁涓嶅瓨鍦ㄥ垯杩斿洖null銆?/p>

2銆佷綅缃俊鎭粠浣曡€屾潵

API骞朵笉鑳戒繚璇佽澶囪繑鍥炵殑鏄儬鍙婁綅缃槸绮剧‘鐨勩€?/p>

璁惧鍙互浣跨敤涓嬪垪鏁版嵁婧?/p>

  • IP鍦板潃
  • 涓夌淮鍧愭爣
    • GPS(Global Positioning System锛屽叏鐞冨畾浣嶇郴缁?锛?/li>
    • 浠嶳FID銆乄i-Fi鍜岃摑鐗欏埌Wi-Fi鐨凪AC鍦板潃锛?/li>
    • GSM鎴朇DMA鎵嬫満鐨処D
  • 鐢ㄦ埛鑷畾涔夋暟鎹?/li>

IP鍦板潃瀹氫綅鏁版嵁鐨勪紭缂虹偣

浼樼偣 缂虹偣
浠讳綍鍦版柟閮藉彲鐢?/td> 涓嶇簿纭?缁忓父鍑洪敊锛屼竴鑸簿纭埌鍩庡競绾?
鍦ㄦ湇鍔″櫒绔鐞?/td> 杩愮畻浠d环澶?/td>

GPS瀹氫綅鏁版嵁鐨勪紭缂虹偣

浼樼偣 缂虹偣
寰堢簿纭?/td> 瀹氫綅鏃堕棿闀匡紝鐢ㄦ埛鑰楃數閲忓ぇ
瀹ゅ唴鏁堟灉涓嶅ソ
闇€瑕侀澶栫‖浠惰澶?/td>

Wi-Fi瀹氫綅鏁版嵁浼樼己鐐?/p>

浼樼偣 缂虹偣
绮剧‘ 鍦ㄤ埂鏉戣繖浜涙棤绾挎帴鍏ョ偣杈冨皯鐨勫湴鍖烘晥鏋滀笉濂?/td>
鍙湪瀹ゅ唴浣跨敤
鍙互绠€鍗曘€佸揩鎹峰畾浣?/td>

鎵嬫満鍦扮悊鏁版嵁浼樼己鐐?/p>

浼樼偣 缂虹偣
鐩稿綋鍑嗙‘ 闇€瑕佽兘澶熻闂墜鏈烘垨鍏秏oden鐨勮澶?/td>
鍙湪瀹ゅ唴浣跨敤 鍦ㄥ熀绔欒緝灏戠殑鐗囨簮鍦板尯鏁堟灉涓嶅ソ
鍙互绠€鍗曘€佸揩鎹峰畾浣?/td>

鐢ㄦ埛鑷畾涔夌殑鍦扮悊瀹氫綅鏁版嵁聽

浼樼偣 缂虹偣
鐢ㄦ埛鍙互鑾峰緱姣旂▼搴忓畾浣嶆湇鍔℃洿鍑嗙‘鐨勪綅缃暟鎹?/td> 鍙兘寰堜笉鍑嗙‘锛岀壒鍒槸褰撶敤鎴蜂綅缃彉鏇村悗
鍏佽鍦扮悊瀹氫綅鏈嶅姟鐨勭粨鏋滀綔涓哄鐢ㄤ綅缃俊鎭?/td>
鐢ㄦ埛鑷杈撳叆鍙兘姣旇嚜鍔ㄦ娴嬫洿蹇?/td>

鐢ㄦ埛鎵€鍦ㄤ綅缃睘浜庢晱鎰熶俊鎭紝HTML5 Geolocation瑙勮寖鎻愪緵浜嗕竴濂椾繚鎶ょ敤鎴烽殣绉佺殑鏈哄埗銆傞櫎闈炲緱鍒?鐢ㄦ埛鏄庣‘璁稿彲锛屽惁鍒欎笉鍙幏鍙栦綅缃俊鎭€?/p>

浜屻€佷娇鐢℅eolocation API

1銆佹祻瑙堝櫒鏀寔妫€鏌?/p>

鐩墠涓绘祦娴忚鍣ㄩ兘鏀寔Geolocation API銆傝鏌ョ湅鏌愪釜鐗堟湰鏄惁鏀寔鍙弬鑰僪ttp://caniuse.com

鐢ㄨ剼鏈鏌ユ敮鎸佹€э細

function loadDemo() {
    if (navigator.geolocation) {
        document.getElementById("support").innerHTML = "Geolocation supported.";
    } else {
        docment.getElementById("support").innerHTML = "Geolocation is not supported in your browser.";
    }
}

聽2銆佷綅缃姹?/p>

鏈変袱绉嶇被鍨嬬殑浣嶇疆瑕佹眰

  • 鍗曟瀹氭湡璇惰姹?/li>
  • 閲嶅鎬х殑浣嶇疆鏇存柊璇锋眰
鍗曟璇锋眰鍑芥暟锛?br>
void getCurrentPosition(in PositionCallback successCallback, 
                             in optional PositionErrorCallback errorCallback,
                             in optional PositionOptions options);
聽鍒嗘瀽涓€涓嬭繖涓牳蹇冨嚱鏁般€?/div>
杩欎釜鍑芥暟閫氳繃navigator.geolocation瀵硅薄璋冪敤銆傝繖涓嚱鏁版湁涓€涓繀閫夊弬鏁板拰涓や釜鍙€夊弬鏁般€?/div>
  • 蹇呴€夊弬鏁皊uccessCallback涓烘祻瑙堝櫒鎸囨槑浣嶇疆鏁版嵁鍙敤鏃跺簲璋冪敤鐨勫嚱鏁般€傚洜涓烘煡浣嶇疆鍙兘闇€瑕佸緢闀挎椂闂达紝鎵€浠ラ噰鐢ㄥ洖璋冨嚱鏁扮殑鏂瑰紡銆傝鍑芥暟鍙湁涓€涓弬鏁帮細浣嶇疆瀵硅薄(鍋囪鍛藉悕涓簆osition)銆傚璞″寘鍚潗鏍囦俊鎭?coords)鍜屼竴涓幏鍙栨暟鎹椂鐨勬椂闂存埑(timestamp)銆?/li>