在近期的一個項目中制作了一個自助機設備導航,根據目前用戶定位信息,按照距離由近到遠展示自助機設備。
頁面是用vue制作的,在代碼中使用:
<script src="https://mapapi.qq.com/web/mapComponents/geoLocation/v/geolocation.min.js"></script>
let geolocation = new qq.maps.Geolocation(“密鑰key", "mapqq", { timeout: 10000,failTipFlag:true });
geolocation.getLocation(this.showPosition, this.showErr)
showPosition(position) {
console.log(position)
const { lng, lat } = position
this.lng = lng
this.lat = lat
this.getDeviceList()
this.initMap(lat, lng)
},
showErr(error) {
console.log('定位失敗')
},
在微信中打開此頁面,蘋果手機沒問題可以正常加載,安卓手機微信中未獲取到定位信息,而使用瀏覽器打開則沒有問題。
經過排查,發現是由於部署的頁面使用的是http協議引起的,部署ssl證書,使用https協議訪問頁面則沒有問題。