昨天获得一个小需求,需要取地理位置。
通过以下的JS能获得经度和纬
if(navigator.geolocation){navigator.geolocation.getCurrentPosition(function (p) {var latitude = p.coords.latitude//纬度var longitude = p.coords.longitude;alert("ss");console.log(p)}, function (e) {//错误信息var aa = e.code + "\n" + e.message;alert(aa);});}
然后将取到经度和纬度传入:http://api.map.baidu.com/geocoder?output=json&location=23.263221,116.663643
获取返回过来的JSON,解析后就取得地点的值
转载于:https://www.cnblogs.com/cxeye/p/4863778.html