zoukankan      html  css  js  c++  java
  • 小程序百度地图使用2

    最近需要做一个类似滴滴打车的叫车小程序,需要用到百度地图的一些方法

    1)获取用户当前位置,并在页面显示当前位置名称,先上代码:

    var that=this;
    var qqmapsdk = new QQmap({
    key: config.Config.key // 必填
    });
    wx.getLocation({
    type: 'gcj02',//默认为 wgs84 返回 gps 坐标,gcj02 返回可用于wx.openLocation的坐标
     
    success: function(res) {
    console.log(res);
    var maker=[{
    iconPath: "../../img/marker.png",
    id: 0,
    latitude: res.latitude,
    longitude: res.longitude,
    28,
    height: 32
    }]
    that.setData({
     
    centerLat:res.latitude,
    centerLon:res.longitude,
    markers:maker
    })
    qqmapsdk.reverseGeocoder({
    location: {
    latitude: res.latitude,
    longitude: res.longitude
    },
    success: function (addressRes) {
    var address = addressRes.result.formatted_addresses.recommend;
    city = addressRes.result.address_component.city;
    that.setData({
    originAddress: address
    })
    }
    })
    },
    })
    wx.getLocation是小程序自带的得到位置的函数,可以得到当前位置的经纬度,但是并不能得到当前位置的名称。需要注意他的type参数决定了返回的经纬度是什么格式,当得到经纬度之后就需要使用百度地图的sdk了
    qqmapsdk.reverseGeocoder这个函数将经纬度转成文字描述,输入坐标返回地理位置信息和附近poi列表。关于这个接口的详细说明请看http://lbs.qq.com/qqmap_wx_jssdk/method-reverseGeocoder.html
     
  • 相关阅读:
    fdisk 分区
    fdisk 添加逻辑分区
    centos7 bond0 双网卡配置
    查看centos7启动项
    本地yum源安装docker
    cobbler Ubuntu16.04 安装
    docker-ce-17.03.2 离线安装RPM包
    day14 生成器的进阶
    day13迭代器与生成器
    day12闭包,装饰器
  • 原文地址:https://www.cnblogs.com/wcxjy/p/8608335.html
Copyright © 2011-2022 走看看