仿滴滴打车百度地图定位查找附近出租车或门店信息

随着技术的发展,开发的复杂度也越来越高,传统开发方式将一个系统做成了整块应用,经常出现的情况就是一个小小的改动或者一个小功能的增加可能会引起整体逻辑的修改,造成牵一发而动全身。通过组件化开发,可以有效实现单独开发,单独维护,而且他们之间可以随意的进行组合。大大提升开发效率低,降低维护成本。

组件化对于任何一个业务场景复杂的前端应用以及经过多次迭代之后的产品来说都是必经之路。组件化要做的不仅仅是表面上看到的模块拆分解耦,其背后还有很多工作来支撑组件化的进行,例如结合业务特性的模块拆分策略、模块间的交互方式和构建系统等等 。

本文给大家介绍的组件是:

前端vue仿滴滴打车百度地图定位查找附近出租车或门店信息, 

 广佛站点小程序体验地址(已上线):

阅读全文下载完整组件代码请关注微信公众号: 前端组件开发

效果图如下:

35dd2797c153001af594eacaf9f481e8.png

f5d639f69aa919660e565808d1db47e8.png

#

#### 使用方法

```使用方法

#安装vue-baidu-map插件

npm install vue-baidu-map --save

<!-- center: 地图中心点 zoom:地图放大比例 -->

<baidu-map v-show="seen" class="bm-view" :center="centerPoint" :zoom="10">

<bm-control class='bmControl'>

<div class="bmTopView">

<!-- 名称 -->

<view class="netView">{{infoName}}

</view>

<!-- 详情 +  打车按钮 -->

<view class="rowView">

<view class="midView">{{infoDetail}}</view>

<view class="locImg" v-show="followIsHide">打车</view>

</view>

</div>

<!-- 我的位置 附近的车图标 -->

<div class="bmBotView">

<image class="userIcon" src="../../static/img/biz/person.svg"></image>

<view class="userName">定位</view>

<image class="userIcon" src="../../static/img/biz/car.svg"></image>

<view class="userName">附近的车</view>

</div>

<view style="height: 2rpx;"></view>

</bm-control>

<!-- 定位点 -->

<bm-marker title="" v-for="(item,index) in netList" :key="100 + index" :data-index="index"

@click="netCurClick(item)" :position="{lng: item.longitude, lat: item.latitude}"

:icon="{url: 'static/img/biz/person.svg', size: {width: 34, height: 34}}">

</bm-marker>

<!-- 附近的车 -->

<bm-marker title="" v-for="(item,index) in nearComList" :key="200 + index" @click="companyCurClick(item)"

:position="{lng: item.longitude, lat: item.latitude}"

:icon="{url: 'static/img/biz/car.svg', size: {width: 34, height: 34}}">

</bm-marker>

</baidu-map>

```

#### HTML代码部分

```html

<template>

<view class="content">

<!-- center: 地图中心点 zoom:地图放大比例 -->

<baidu-map v-show="seen" class="bm-view" :center="centerPoint" :zoom="10">

<bm-control class='bmControl'>

<div class="bmTopView">

<!-- 名称 -->

<view class="netView">{{infoName}}

</view>

<!-- 详情 +  打车按钮 -->

<view class="rowView">

<view class="midView">{{infoDetail}}</view>

<view class="locImg" v-show="followIsHide">打车</view>

</view>

</div>

<!-- 我的位置 附近的车图标 -->

<div class="bmBotView">

<image class="userIcon" src="../../static/img/biz/person.svg"></image>

<view class="userName">定位</view>

<image class="userIcon" src="../../static/img/biz/car.svg"></image>

<view class="userName">附近的车</view>

</div>

<view style="height: 2rpx;"></view>

</bm-control>

<!-- 定位点 -->

<bm-marker title="" v-for="(item,index) in netList" :key="100 + index" :data-index="index"

@click="netCurClick(item)" :position="{lng: item.longitude, lat: item.latitude}"

:icon="{url: 'static/img/biz/person.svg', size: {width: 34, height: 34}}">

</bm-marker>

<!-- 附近的车 -->

<bm-marker title="" v-for="(item,index) in nearComList" :key="200 + index" @click="companyCurClick(item)"

:position="{lng: item.longitude, lat: item.latitude}"

:icon="{url: 'static/img/biz/car.svg', size: {width: 34, height: 34}}">

</bm-marker>

</baidu-map>

</view>

</template>

```

#### JS代码 (引入组件 填充数据)

```javascript

<script>

import Vue from 'vue'

import BaiduMap from 'vue-baidu-map'

import {

BmlMarkerClusterer

} from 'vue-baidu-map'

Vue.use(BaiduMap, {

// ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */

ak: 'dEctYrTTeVr76ANfzG7XwYZGPj'

});

export default {

components: {

},

data() {

return {

nearComList: [], // 附近商机列表

infoName: '',

infoDetail: '',

tabbarIsHide: false,

followIsHide: false,

seen: true,

netList: [],

netItem: {},

// 中心坐标 {lng: 113.282202, lat:23.13771 }

centerPoint: {

lng: 113.282202,

lat: 23.13771

}

};

},

mounted: function(e) {

let myThis = this;

this.netItem = {

'orgName': '我的地址',

'orgAddr': '详细地址',

'longitude': '113.22',

'latitude': '23.12'

};

this.netList.push(this.netItem);

          this.infoName = this.netItem.orgName;

          this.infoDetail = this.netItem.orgAddr;

this.nearComList = [{

'comName': '车名称',

'comAddr': '车详细地址',

'longitude': '113.262',

'latitude': '23.2128'

},

{

'comName': '车名称2',

'comAddr': '车详细地址2',

'longitude': '113.532632',

'latitude': '23.1228'

},

{

'comName': '车名称3',

'comAddr': '车详细地址3',

'longitude': '113.42632',

'latitude': '23.1228'

},

{

'comName': '车名称4',

'comAddr': '车详细地址4',

'longitude': '113.327632',

'latitude': '23.16228'

},

{

'comName': '车名称5',

'comAddr': '车详细地址5',

'longitude': '113.324632',

'latitude': '23.3228'

},

{

'comName': '车名称6',

'comAddr': '车详细地址6',

'longitude': '113.1632',

'latitude': '23.2228'

}

];

},

methods: {

showOrHideTabbar() {

this.tabbarIsHide = !this.tabbarIsHide;

if (this.tabbarIsHide) {

uni.hideTabBar();

} else {

uni.showTabBar();

}

},

netCurClick(item) {

this.followIsHide = false;

this.infoName = this.netItem.orgName;

this.infoDetail = this.netItem.orgAddr;

},

companyCurClick(item) {

this.followIsHide = true;

this.infoName = item.comName;

this.infoDetail = item.comAddr;

console.log('客户坐标item = ' + JSON.stringify(item));

},

// 计算两点附近距离

getDistance(lat1, lng1, lat2, lng2) {

let EARTH_RADIUS = 6378.137;

let radLat1 = this.rad(lat1);

let radLat2 = this.rad(lat2);

let a = radLat1 - radLat2;

let b = this.rad(lng1) - this.rad(lng2);

let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +

Math.cos(radLat1) * Math.cos(radLat2) *

Math.pow(Math.sin(b / 2), 2)));

s = s * EARTH_RADIUS;

//s = Math.round(s * 10000d) / 10000d;

s = Math.round(s * 10000) / 10000;

s = s * 1000; //乘以1000是换算成米

return s;

},

rad(d) {

return d * Math.PI / 180.0;

},

},

};

</script>

```

#### CSS

```CSS

<style>

.content {

display: flex;

flex-direction: column;

width: 100%;

height: 100%;

overflow: hidden;

}

/* 搜索 */

.topView {

margin-top: 2px;

width: 100%;

height: 56px;

display: flex;

flex-direction: row;

}

.uni-search {

text-align: center;

justify-content: center;

width: 88%;

height: 30px;

background-color: #F2F2F2;

}

.changeIcon {

margin-left: -2px;

margin-top: 27rpx;

width: 12%;

height: 24px;

}

/* .mySwitch {

width: 208rpx;

margin-left: 3px;

height: 56rpx;

margin-top: 22rpx;

} */

/* 地图 */

.bm-view {

width: 100%;

height: calc(100vh - 154px);

}

/* 自定义控件 */

.bmControl {

margin-top: calc(100vh - 284px);

width: 100vw;

margin-left: 0vw;

height: 90px;

background-color: white;

border-radius: 8rpx;

}

.bmTopView {

display: flex;

flex-direction: column;

margin-left: 26rpx;

margin-top: 12rpx;

width: 100%;

height: 112rpx;

}

.rowView {

display: flex;

flex-direction: row;

}

.netView {

font-size: 16px;

font-weight: 500;

color: #333333;

line-height: 26px;

font-family: PingFangSC-Semibold, PingFang SC;

}

.midView {

display: flex;

flex-direction: row;

margin-left: 6rpx;

color: #666666;

width: 70%;

height: 60rpx;

line-height: 50rpx;

font-size: 13px;

}

.locImg {

margin-left: 2px;

margin-top: 0rpx;

width: 74px;

height: 30px;

background-color: #1677FF;

border-radius: 32px;

color: #FFFFFF;

text-align: center;

line-height: 30px;

}

.bmBotView {

display: flex;

flex-direction: row;

margin-left: 6rpx;

height: 36px;

}

.bmBotleftView {

width: 70%;

display: flex;

flex-direction: row;

}

.userIcon {

margin-left: 24rpx;

margin-top: 4rpx;

width: 20px;

height: 20px;

}

.userName {

text-align: center;

margin-left: 2px;

margin-top: 0rpx;

width: auto;

height: 24px;

line-height: 24px;

font-size: 26rpx;

color: #999999;

border-radius: 3px;

}

.pullScrollView {

display: flex;

flex-direction: column;

height: auto;

width: 100%;

background-color: #F2F2F2;

}

.uni-list {

margin-top: 0px;

height: 100%;

}

.uni-list-cell {

display: flex;

flex-direction: column;

margin-bottom: 12px;

width: 91%;

margin-left: 4.5%;

height: auto;

background-color: #FFFFFF;

border-radius: 12rpx;

}

.list-text {

margin-left: 34rpx;

line-height: 44px;

width: 100%;

font-size: 32rpx;

color: #333333;

height: 44px;

}

.list-textDetail {

margin-left: 34rpx;

line-height: 40rpx;

width: 100%;

font-size: 28rpx;

color: #666666;

height: 40rpx;

margin-bottom: 40rpx;

}

.checkbtn {

margin-top: -12px;

margin-left: 8px;

text-align: center;

width: 160rpx;

font-size: 26rpx;

color: #1677FF;

background-color: #E7F1FF;

height: 34px;

line-height: 34px;

border-radius: 34rpx;

}

</style>

```

 广佛站点小程序体验地址(已上线):

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
因为最近项目需要,用了3个星期研究了一下百度地图的官方demo,并基于其源代码做了一定的修改,部分模仿了官方版的百度地图V5.3.1(version code: 431,目前最新版是6.0.1)的界面。现放出源代码供大家学习研究,修改版例子中的代码已经尽可能注释了,不过本人水平有限,代码质量可能有待提高,请大家勿用于商业用途,因为可能有很多未知BUG。觉得好的话请大家顶! 开发环境: eclipse:Android Developer Tools Build: v22.0.1-685705 JDK:java version "1.7.0_03" 测试环境: 三星GT-i9228 android2.3.6 主要改动: 1、LayersDemo里面把“普通图、卫星图及交通流量图”集成到了PreferencesActivity里面,修改立即生效。 2、MapControlDemo里面把“缩放级别、旋转、俯视”集成到了PreferencesActivity里面,修改立即生效。把截图功能加到了menu里面。 PS:这里顺便说一下新版百度地图怎么控制俯视角度,我查了好久,连官方的手势说明都没找到,被我无意之间发现了:两只手指同时向下滑为俯视,同时向上为恢复,当然也可以点击地图左上角的指南针 3、UISettingsDemo里面把“缩放、平移、双击放大、旋转” 开关手势功能和显示隐藏“缩放控件、指南针位置”UI控件集,成到了PreferencesActivity里面,修改立即生效。 4、LocationOverlayDemo里面增加了比例尺和自定义缩放控件。 5、OverlayDemo只做了位置修改,下面的两个才是重头戏。 6、RoutePlanDemo模仿百度地图5.3.1的路径规划。 7、OfflineDemo模仿百度地图5.3.1的离线地图,并集成到一个界面了。 如有问题请参照百度文档,或者联系我QQ472950043。 模仿的版本是百度地图5.3.1 ,大家有需要的话可以到豌豆荚下载历史版本里面下载baiduditu_431.apk

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端组件开发

你的钟意将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值