标签:
网址:www.cnblogs.com/phillyx/p/4534268.html
<!--废弃-->
<!--<script type="text/javascript" src="http://api.map.baidu.com/api?type=quick&ak=你的key&v=1.0"></script>-->
(function($) {
/**
* @description 获取百度定位信息
* @param {Function} callback
*/
function getPosition(callback) {
try {
plus.geolocation.getCurrentPosition(function(position) {
console.log(JSON.stringify(position));
var codns = position.coords; //获取地理坐标信息;
// var geoc = new BMap.Geocoder();
// var pt = new BMap.Point(codns.longitude, codns.latitude);
// geoc.getLocation(pt, function(rs) {
// var addComp = rs.addressComponents;
// console.log(JSON.stringify(addComp));
// var lo =addComp.province+‘,‘+addComp.city;
// callback(lo);
// });
var req = ‘http://api.map.baidu.com/geocoder/v2/‘;
var parms = {
ak: ‘你的key‘,
callback: ‘renderReverse‘,
output: ‘json‘,
location: codns.latitude + ‘,‘ + codns.longitude
//,pois:1(周边poi数组) //不建议要,周边数据太杂,不需要
};
mui.ajax(req, {
data: parms,
dataType: ‘json‘, //服务器返回json格式数据
type: ‘post‘, //HTTP请求类型
timeout: 10000, //超时时间设置为10秒;
success: function(data) {
console.log(JSON.stringify(data));
myStorage.setItem(‘geolocation‘,data);
if (data.status == 0) {
var lo = data.result.addressComponent.province + ‘,‘ + data.result.addressComponent.city;
callback(lo);
} else {
callback(false);
}
},
error: function(xhr, type, errorThrown) {
callback(false);
}
});
}, function(e) {
console.log("获取定位位置信息失败:" + e.message);
callback(false);
}, {
provider: ‘baidu‘
});
} catch (e) {
callback(false);
console.error(e.message);
}
}
$.getbaiduposition = getPosition;
}(mui));
标签:
原文地址:http://www.cnblogs.com/movemoon/p/4832901.html