codecamp

百度智能小程序 宿主App内置地图查看位置

swan.openLocation

解释:使用宿主 App 内置地图查看位置。

方法参数

Object object

object 参数说明

属性名类型必填默认值说明

latitude

Number

纬度,范围为 -90~90 ,负数表示南纬。

longitude

Number

经度,范围为 -180~180 ,负数表示西经。

scale

Number

缩放比例,范围 5~18 ,默认为 18 。

name

String

位置名

ignoredApps

Array

定义在拉起的地图 App 面板中需要被屏蔽的地图类 App 。

address

String

地址的详细说明

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

ignoredApps 参数说明

类型说明

GaodeMap

String

当用户手机端安装了高德地图应用时,openLocation 打开地图点击路线拉起的支持地图应用列表中将包含高德地图,可以在 ignoredApps 数组中传入该值用以屏蔽面板中的高德地图应用。

AppleMap

String

ios 用户调用 openLocation 打开地图,点击路线拉起的支持地图应用列表中将包含苹果地图,可以在 ignoredApps 数组中传入该值用以屏蔽面板中的苹果地图应用。

示例


图片示例

代码示例: 

在开发者工具中打开

<view class="wrap">
    <view class="card-area">
        <view class="list-area border-bottom">
            <view class="list-item-key-4">经度</view>
            <view class="list-item-value">116°27′</view>
        </view>
        <view class="list-area border-bottom">
            <view class="list-item-key-4">纬度</view>
            <view class="list-item-value">40°04′</view>
        </view>
        <view class="list-area border-bottom">
            <view class="list-item-key-4">缩放比例</view>
            <view class="list-item-value">{{locationInfo.scale}}</view>
        </view>
        <view class="list-area border-bottom">
            <view class="list-item-key-4">位置名称</view>
            <view class="list-item-value">{{locationInfo.name}}</view>
        </view>
         <view class="list-area border-bottom">
            <view class="list-item-key-4">地址</view>
            <view class="list-item-value">{{locationInfo.address}}</view>
        </view>
        <view class="button-group">
            <button class="button" bindtap="openLocation" type="primary" loading="{{loading}}">查看位置地图</button>
        </view>
    </view>
</view>

    Page({
        data: {
            title: 'openLocation',
            loading: false,
            locationInfo: {
                latitude: 40.04,
                longitude: 116.27,
                scale: 18,
                name: '百度科技园',
                address: '北京市海淀区西北旺东路10号院'
            }
        },
        openLocation () {
            let locationInfo = this.data.locationInfo;
            swan.openLocation({
                latitude: locationInfo.latitude,
                longitude: locationInfo.longitude,
                scale: 18,
                name: locationInfo.name,
                address: locationInfo.address,
                success: res => {
                    console.log('openLocation success', res);
                },
                fail : err => {
                    swan.showToast({
                        title: '检查位置权限',
                        icon: 'none'
                    })
                    console.log('openLocation fail', err);
                }
            });
        }
    });

    错误码

    iOS

    错误码说明

    202

    解析失败,请检查参数是否正确。

    常见问题

    Q:百度小程序支持导航吗?或是支持调起其它导航 APP ?

    A:不支持导航,可以使用 openLocation 打开宿主 app 内置的地图导航。


    百度智能小程序 获取当前的地理位置和速度
    百度智能小程序 打开地图选择位置
    温馨提示
    下载编程狮App,免费阅读超1000+编程语言教程
    取消
    确定
    目录

    百度智能小程序开发文档

    百度智能小程序 组件

    百度智能小程序 地图

    百度智能小程序 画布

    百度智能小程序 API

    百度智能小程序 界面

    百度智能小程序 关注小程序引导组件

    百度智能小程序 自定义组件

    百度智能小程序 媒体

    百度智能小程序 设备

    百度智能小程序 拨打电话

    百度智能小程序 内存警报

    百度智能小程序 手机联系人

    百度智能小程序 用户截屏事件

    百度智能小程序 第三方平台

    百度智能小程序 开放接口

    百度智能小程序 百度收银支付

    百度智能小程序 分包预下载

    百度智能小程序 数据分析

    百度智能小程序 服务端

    百度智能小程序 云开发

    百度智能小程序 初始化

    百度智能小程序 云函数

    百度智能小程序 服务端初始化

    百度智能小程序 服务器获取上下文

    百度智能小程序 服务端云函数

    百度智能小程序 开发教程

    百度智能小程序 功能开发

    百度智能小程序 基本原理

    百度智能小程序 小程序自动化

    百度智能小程序 视频教程

    关闭

    MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }