腾讯地图有一个组件:http://lbs.qq.com/tool/component-geolocation.html
来到 调用方式二
<style lang="less"> </style> <template> <div> <iframe id="geoPage" width=0 height=0 frameborder=0 style="display:none;" scrolling="no" src="https://apis.map.qq.com/tools/geolocation?key=xxxx&referer=xxxx"> </iframe> </div> </template> <script> export default { data() { return { loc: '' } }, created() { this.Tmap() }, methods: { Tmap() { window.addEventListener('message', function(event) { if (event.data) { this.loc = event.data // 接收位置信息 if (this.loc) { console.log(this.loc.lat) console.log(this.loc.lng) } } }, false) // 设置6s超时,防止定位组件长时间获取位置信息未响应 setTimeout(function() { if (!this.loc) { console.log('定位超时') } }, 6000) // 6s为推荐值,业务调用方可根据自己的需求设置改时间,不建议太短 } } } </script>
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- azee.cn 版权所有 赣ICP备2024042794号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务