获取用户定位
[!TIP|labelVisibility:hidden|iconVisibility:hidden] getUserLocation(ref, callback)
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
ref | String | 是 | 地图节点 |
callback | Function | 否 | 回调函数 |
callback
函数会返回一个对象,其属性包含以下一项或多项:
success
(Boolean)true
-- 成功false
-- 失败
message
(String) -- 成功或者失败的相关信息data
(Object) -- 数据对象,其属性包含以下一项:latitude
(Number / 必选) -- 高德坐标系下坐标点的纬度longitude
(Number / 必选) -- 高德坐标系下坐标点的经度
示例代码
<template>
<div class="wrapper">
<hcm-amap class="map" ref="map"
:zoomLevel="map.zoomLevel"
:showScale="map.showScale"
:center="map.center"
:showPositioning="map.showPositioning"
:showUserLocation="true">
</hcm-amap>
<text class="close" @click="close">关闭</text>
</div>
</template>
<script>
const modal = weex.requireModule('modal')
const amap = weex.requireModule('amap')
// const stream = weex.requireModule('stream')
export default {
data () {
return {
map: {
zoomLevel: 16,
showScale: false,
showPositioning: true,
showUserLocation: false,
center: {
latitude: 30.238753,
longitude: 120.145336
}
}
}
},
mounted () {
amap.getUserLocation(this.$refs.map, function (res) {
modal.alert({
message: JSON.stringify(res)
})
})
},
methods: {
close () {
amap.close()
}
}
}
</script>
<style scoped>
.wrapper {
flex: 1;
}
.map {
flex: 1;
}
.close {
position: absolute;
top: 40px;
right: 30px;
width: 88px;
height: 88px;
background-color: white;
text-align: center;
line-height: 88px;
font-size: 30px;
border-radius: 44px;
}
</style>