好久沒用過h5新api地理定位——navigator.geolocation,
就在前幾天,,,
發現,不能用了???(谷歌被牆了,陷入悲傷)
整個人都懵逼,項目需要定位啊,,,懵逼,,,
然后就寫了三天,tm的寫不出來,今天終於,,,
直接上代碼咯。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>標題</title>
<meta name="keywords" content="">
<meta name="description" content="">
<script src="jquery-1.8.3.min.js"></script>
</head>
<body>
<script>
$(function(){
var latlon=null;
//ajax獲取用戶所在經緯度
$.ajax({
url:"http://api.map.baidu.com/location/ip?ak=bFNYmleHunu49WxpIlCN8QxTpzs93c8V&coor=bd09ll",
type:"POST",
dataType:"jsonp",
success:function(data){
latlon=data.content.point.y+","+data.content.point.x;
//ajax根據經緯度獲取省市區
$.ajax({
type: "POST",
dataType: "jsonp",
url: 'http://api.map.baidu.com/geocoder/v2/?ak=C93b5178d7a8ebdb830b9b557abce78b&callback=renderReverse&location='+latlon+'&output=json&pois=0',
success: function (json) {
if(json.status==0){
console.log(json.result.addressComponent.district);
}
}
});
}
});
});
</script>
</body>
</html>
但是我能說這定位的真的很不准嗎,簡直都是錯的,但是目前只能利用瀏覽器這樣定位了,誰要能准確定位,求教!!!
好了,下班。