wx.config({
debug: false,
appId: "", // 必填,公眾號的唯一標(biāo)識
timestamp: "", //必填,生成簽名的時間戳
nonceStr: "", // 必填,生成簽名的隨機(jī)串
signature: "",// 必填,簽名,見附錄1
jsApiList: [ // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
"getLocation",
"openLocation"
]
});
wx.ready(function(){
wx.getLocation({
type: 'wgs84', // 默認(rèn)為wgs84的gps坐標(biāo),如果要返回直接給openLocation用的火星坐標(biāo),可傳入'gcj02'
success: function (res) {
var latitude = res.latitude; // 緯度,浮點數(shù),范圍為90 ~ -90
var longitude = res.longitude; // 經(jīng)度,浮點數(shù),范圍為180 ~ -180。
var speed = res.speed; // 速度,以米/每秒計
var accuracy = res.accuracy; // 位置精度
$('#location').click(function(){
position(latitude,longitude);
})
//position(latitude,longitude);
}
});
});
function position(latitude,longitude){
$.ajax({
type:"",
data: {
latitude:latitude,
longitude:longitude
},
async: false,
dataType:"json",
success:function(data){
x = data.position.x;
y = data.position.y;
}
})
var point = new BMap.Point(x,y);
// alert(point);
// map.centerAndZoom(point,12);
var geoc = new BMap.Geocoder();
var pt = point;
geoc.getLocation(pt, function(rs){
var addComp = rs.addressComponents;
var location = addComp.city + ", " + addComp.district + ", " + addComp.street;
$('#location').text(location);
// alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
});