赞
踩
1.index.html 引用
<script type="text/javascript" src="//api.map.baidu.com/api?v=3.0&ak=你的key"></script>
2.页面使用
- const state = reactive({
- city:''
- });
- const getCurrentCity = () => {
- // const map = new BMap.Map();
- // 获取当前城市
- const geolocation = new BMap.Geolocation();
- geolocation.getCurrentPosition((position) => {
- const point = position.point;
-
- // 根据坐标获取城市名
- const geoc = new BMap.Geocoder();
- geoc.getLocation(point, (result) => {
- if (result) {
- state.city = result.addressComponents.city || '长春';
- weather(state.city)
- }
- });
- });
- };
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。