浙里办通过ip获取位置

    // // 通过ip定位.获取到当前城市名称
    var myCity = new window.BMap.LocalCity()
    var lat, lng
    myCity.get(async (res) => {
      lat = res.center.lat
      lng = res.center.lng
      console.log(lat)
      console.log(lng)
      const point = new BMap.Point(lng, lat)
      const gc = new BMap.Geocoder()
      gc.getLocation(point, function(rs) {
        const addComp = rs.addressComponents
        const address = rs.address //得到当前地址
        console.log(address, "地址", addComp)
      })
    })

 

posted on 2022-03-10 13:38  危险*  阅读(175)  评论(0编辑  收藏  举报