• uniapp微信小程序地图实现周边


    官方说明:小程序JavascriptSDK使用指南 - 微信小程序解决方案 | 腾讯位置服务icon-default.png?t=N7T8https://lbs.qq.com/product/miniapp/jssdk/

    1. 先申请腾讯地图的开发者密钥,申请地址:腾讯位置服务 - 立足生态,连接未来

    2. 申请密钥时,需要勾选webServiceAPI和微信小程序

    3. 下载微信小程序JavaScriptSDK,微信小程序JavaScriptSDK v1.0,解压后,将qqmap-wx-jssdk.min.js放入到项目目录中

    4. 在点击需要查询的配套设施时,调用search方法,设置搜索条件keyword和location

    5. 在回调success中,将返回的结果通过marker标到地图上,或者以文本的形式展示在列表中

    效果展示:

    调用qqmapsdk.search方法

    1. qqmapsdk.search({
    2. keyword: name,//搜索周边poi,比如:“酒店” “餐饮” “娱乐” “学校” 等等
    3. page_size: 5, //每页条目数,最大限制为20条,默认值10
    4. location: that.mapxx.latitude + ',' + that.mapxx.longitude,//①String格式:lat<纬度>,lng<经度>(例:location: ‘39.984060,116.307520’)
    5. success: function(res) { //搜索成功后的回调
    6. wx.hideToast({});
    7. let arrlist = [];
    8. for (var i = 0; i < res.data.length; i++) {
    9. arrlist.push({ // 获取返回结果,放到mks数组中
    10. title: res.data[i].title,
    11. latitude: res.data[i].location.lat,
    12. longitude: res.data[i].location.lng,
    13. distance: res.data[i]._distance,
    14. })
    15. }
    16. // 每次不用重新赋值,通过下标给需要的赋值
    17. that.peripheralsData = arrlist;//前台需要展示的数组
    18. },
    19. fail: function(res) {
    20. console.log(res);
    21. },
    22. complete: function(res) {
    23. }
    24. });

    周边配套设置的完整代码部分

    HTML

    1. <view class="infoBox_peripherals">
    2. <view class="infoBox_peripherals_title">
    3. <view class="infoBox_peripherals_title__left">
    4. <view class="infoBox_peripherals_title__left_bgbox">view>
    5. <view>周边配套view>
    6. view>
    7. view>
    8. <view class="infoBox_peripherals_mapbox">
    9. <map class="infoBox_peripherals_mapbox__map" id="map" :latitude="mapxx.latitude" :longitude="mapxx.longitude"
    10. :scale="mapxx.scale" :markers="mapxx.markers"
    11. >map>
    12. view>
    13. <view class="infoBox_peripherals_tabs">
    14. <u-tabs :list="list"
    15. :current="tabsCurrent"
    16. @click="tabsClick"
    17. >u-tabs>
    18. view>
    19. <view class="infoBox_peripherals_tabsitem">
    20. <view v-for="(item,index) in peripheralsData" :key="index" class="infoBox_peripherals_tabsitem_items">
    21. <view class="infoBox_peripherals_tabsitem_items_left">
    22. <image src="../../static/index/location-icon1@2x.png" style="width: 26rpx;height: 34rpx;">image>
    23. <view class="infoBox_peripherals_tabsitem_items_left_text">{{item.title}}view>
    24. view>
    25. <view class="infoBox_peripherals_tabsitem_items_right">{{item.distance}}mview>
    26. view>
    27. view>
    28. view>

    CSS

    1. // 周边设备
    2. &_peripherals{
    3. background: #FFFFFF;
    4. box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(0, 0, 0, 0.05);
    5. border-radius: 16rpx;
    6. margin-bottom: 80rpx;
    7. &_title{
    8. display: flex;
    9. justify-content: space-between;
    10. padding: 14px 12px;
    11. font-size: 14px;
    12. letter-spacing: 1px;
    13. &__left{
    14. display: flex;
    15. font-size: 24rpx;
    16. font-weight: 600;
    17. color: #00A39C;
    18. &_bgbox{
    19. width: 6rpx;
    20. height: 28rpx;
    21. background: #00A39C;
    22. border-radius: 3rpx;
    23. margin-right: 12rpx;
    24. }
    25. }
    26. &__right{
    27. font-weight: 600;
    28. &__green{
    29. color:#00AF99;
    30. }
    31. &__yellow{
    32. color:#FBAD00;
    33. }
    34. }
    35. }
    36. &_mapbox{
    37. width: 100%;
    38. height: 400rpx;
    39. border-radius: 12rpx;
    40. padding: 12px 14px;
    41. box-sizing: border-box;
    42. display: flex;
    43. justify-content: center;
    44. align-items: center;
    45. background-color: #fff;
    46. &__map{
    47. height: 398rpx;
    48. width: 100%;
    49. border-radius: 5px;
    50. background-color: #fff;
    51. }
    52. }
    53. &_tabs{
    54. // padding: 12px 14px;
    55. }
    56. &_tabsitem{
    57. padding: 14px 12px;
    58. &_items{
    59. display: flex;
    60. align-items: center;
    61. justify-content: space-between;
    62. margin-bottom: 18rpx;
    63. &_left{
    64. display: flex;
    65. align-items: center;
    66. font-size: 28rpx;
    67. font-weight: 400;
    68. color: #333333;
    69. &_text{
    70. margin-left: 10rpx;
    71. }
    72. }
    73. &_right{
    74. font-size: 24rpx;
    75. font-weight: 400;
    76. color: #999999;
    77. }
    78. }
    79. }
    80. }

    JS

  • 相关阅读:
    tomcat的负载均衡、动静分离(nginx联动)
    【大数据】计算引擎:Spark核心概念
    【今天聊聊生产力】提升研发生产力的神器推荐
    土壤温湿度传感器
    浅谈综合管廊建设提速后的运维管理
    噪声系数与插入损耗
    IDEA中创建编写JSP
    Spring Cloud Loadbalancer
    浪潮服务器重置密码方法
    电脑硬盘数据恢复一般需要收费多少钱
  • 原文地址:https://blog.csdn.net/qq_43080548/article/details/132898660