http://lbs.qq.com/webservice_v1/guide-search.htmlhtml
Html5獲取地理位置信息是經過Geolocation API提供,使用其getCurrentPosition方法,此方法中有三個參數,分別是成功獲取到地理位置信息時所執行的回調函數,失敗時所執行的回調函數和可選屬性配置項。在獲取地理位置信息前,首先瀏覽器都會向用戶詢問是否願意共享其位置信息,待用戶贊成後才能使用。java
function getLocation() { if (navigator.geolocation){ navigator.geolocation.getCurrentPosition(showPosition,showError); } else{x.innerHTML="Geolocation is not supported by this browser.";} } function showPosition(position) { x.innerHTML="當前經度: " + position.coords.longitude + "<br />當前緯度: " + position.coords.latitude; } function showError(error){ switch(error.code) { case error.PERMISSION_DENIED: x.innerHTML="User denied the request for Geolocation." break; case error.POSITION_UNAVAILABLE: x.innerHTML="地址信息不合法" break; case error.TIMEOUT: x.innerHTML="請求超時." break; case error.UNKNOWN_ERROR: x.innerHTML="不知名錯誤" break; } } getLocation();
$.ajax({ type : 'get', url : 'http://apis.map.qq.com/ws/geocoder/v1', dataType:'jsonp', data : { key:"QEPBZ-LQHW4-476UC-X7WAY-MHRT5-K7BZM",//開發密鑰 location:"32.078857,118.77397",//位置座標 get_poi:"1",//是否返回周邊POI列表:1.返回;0不返回(默認) coord_type:"1",//輸入的locations的座標類型,1 GPS座標 parameter:{"scene_type":"tohome","poi_num":20},//附加控制功能 output:"jsonp" }, success : function(data, textStatus) { if(data.status == 0){ var address = data.result.formatted_addresses.recommend; $("#address").html(address); }else { alert("系統錯誤,請聯繫管理員!") } }, error : function() { alert("系統錯誤,請聯繫管理員!") } });