要使用手機,獲取在微信公眾號工具中測試
/* 定位 */
function getAddress() {
console.log('getAddress');
//接口返回的配置參數
getLocations(function (res) {
if (res.ret == 200) {
wx.config({
debug: false, // 開啟調試模式,調用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數,可以在pc端打開,參數信息會通過log打出,僅在pc端時才會打印。
appId: res.data.appId, // 必填,公眾號的唯一標識
timestamp: res.data.timestamp, // 必填,生成簽名的時間戳
nonceStr: res.data.nonceStr, // 必填,生成簽名的隨機串
signature: res.data.signature,// 必填,簽名,見附錄1
jsApiList: ['getLocation'] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
});
}
});
}
wx.error(function (res) {
console.log(res);
});
wx.ready(function () {
wx.getLocation({
type: 'wgs84', // 默認為wgs84的gps坐標,如果要返回直接給openLocation用的火星坐標,可傳入'gcj02'
success: function (res) {
var latitude = res.latitude; // 緯度,浮點數,范圍為90 ~ -90
var longitude = res.longitude; // 經度,浮點數,范圍為180 ~ -180。
var speed = res.speed; // 速度,以米/每秒計
var accuracy = res.accuracy; // 位置精度
//轉換經緯度
changeLogLat(longitude, latitude);
//百度經緯度轉換
//http://api.map.baidu.com/geoconv/v1/?coords=' + log + ',' + lat + '&from=1&to=5&ak=密鑰'
}
});
});