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


前端vue仿滴滴打车百度地图定位查找附近出租车或门店信息, 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12982

效果图如下:


#

#### 使用方法

```使用方法

<!-- 官方文档: https://dafrok.github.io/vue-baidu-map/#/zh/start/base -->

#安装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>

```

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,546评论 6 507
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,224评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,911评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,737评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,753评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,598评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,338评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,249评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,696评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,888评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,013评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,731评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,348评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,929评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,048评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,203评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,960评论 2 355

推荐阅读更多精彩内容