国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
導(dǎo)航彈框
騰訊
app url
web url
百度
Home Web Front-end uni-app Use uniapp to develop a simple map navigation

Use uniapp to develop a simple map navigation

Jun 09, 2022 pm 07:46 PM
uni-app

How to use uniapp to develop a simple map navigation? This article will provide you with an idea for making a simple map. I hope it will be helpful to you!

Use uniapp to develop a simple map navigation

Let’s take a look at the renderings first

Use uniapp to develop a simple map navigation

Use uniapp to develop a simple map navigation

##Simple map

In the map in Figure 1, you can see that point a is connected to point b, basic information and basic controls (zoom in, zoom out, return to a specified point). Next, we will proceed step by step explain.

Required configuration

needs to be in

app module in manifest.json Configure the map and add the key of the relevant map. If not, you can apply on the relevant developer platform

Use uniapp to develop a simple map navigation

After configuring this part, you can start using the map Component

Map marker points

To create marker points in uniapp map, you need to use an attribute

markers .

Let’s first take a look at the common attributes of

markers

NameDescription TypeRequired##idlatitudelongitude##iconPathDisplayed iconstringfalsecalloutCustomize the bubble box above the mark pointObjectfalselabelAdd a label to the marked pointObjectfalseFor more information, please check:
Mark point id number true
latitude number true
Longitude number true
https://uniapp.dcloud.io/component/map.html

After understanding these, we can use

markers
The attribute creates marker points.

markersThe attribute is of array type, so marker points should be created like this

    this.covers = [ 
        {
            id: 1,
            latitude: 34.7486,
            longitude: 113.6709,
            iconPath: '../../static/shop.png',
            title: "目的地"
        }
    ];
If you want to add more marker points, you can continue to add them in the array. object

,

Each object

represents a marking point

mount

    <map :markers="covers"></map>

Coordinate connection

If we want to connect our coordinates, we need to use the polyline

attribute.

Let’s take a look at the common attributes of polyline

##NameDescription##pointsArray of latitude and longitudeArraytrue colorThe color of the linestringfalsewidthLine widthNumberfalseiconPathDisplayed iconstring falsearrowLineLine with arrowBooleanfalsecolorListRainbow displayArrayfalse

平臺(tái)差異請(qǐng)查看

https://uniapp.dcloud.io/component/map.html#app平臺(tái)地圖服務(wù)商差異

這里我們要注意 兩個(gè)坑,作者親踩

  • polyline 屬性是一個(gè)數(shù)組

    polyline 之所以是一個(gè)數(shù)組是因?yàn)樗梢酝瑫r(shí)創(chuàng)建多條線并且連線,每條線還可以有著不同的顏色、箭頭、圖標(biāo)等。

  • points 也是一個(gè)數(shù)組

    points之所以是一個(gè)數(shù)組是因?yàn)樗_定某一條線上的每一個(gè)點(diǎn),且每個(gè)點(diǎn)都應(yīng)該由經(jīng)緯度構(gòu)成

所以 polyline 的正確寫法應(yīng)該是這樣的

    // 連線
    this.polyline = [
        // 第一條線
        {
            // 每個(gè)點(diǎn)的經(jīng)緯度
            points: [{34.7486, 113.6709}, {28.7486, 113.6709}],
            // 顏色
            color: "#000",
            // 寬度
            width: 10
        }
    ]

如果想添加第二條線僅僅只需要在 polyline 中在添加一個(gè) Object。掛載

    <map :polyline="polyline"></map>

放大縮小

map 的放大縮依賴于 scale 屬性 所以只需要?jiǎng)討B(tài)改變 scale 屬性的值就可以了。 但這里要注意 scale 的取值范圍為 3~20,數(shù)字類型

這就是放大縮小功能的依賴

Use uniapp to develop a simple map navigation

回到指定位置

想要地圖回到指定的位置也非常簡(jiǎn)單,只需要使用 uni.createMapContext() 方法創(chuàng)建一個(gè) mapContent 對(duì)象 在使用 附帶的 moveToLocatio 方法便可讓地圖回到指定的位置。

// 回到定位點(diǎn)
goBackToLocation() {
   uni.createMapContext("map").moveToLocation({34.7486, 113.6709});
},

Use uniapp to develop a simple map navigation

導(dǎo)航彈框

圖二中的地圖應(yīng)用選擇彈框則是使用了 h5Plus

nativeUI.actionSheet 方法 創(chuàng)建了彈框

runtime.openURL 方法 打開了 導(dǎo)航軟件 或 h5 頁面導(dǎo)航

nativeUI情請(qǐng)查看

https://www.html5plus.org/doc/zh_cn/nativeui.html

runtime情請(qǐng)查看

https://www.html5plus.org/doc/zh_cn/runtime.html

    // 導(dǎo)航 會(huì)打開導(dǎo)航菜單供用戶選擇
    openNavigation(longitude, latitude, name) {
        let url = ""; // app url
        let webUrl = ""; // web url 用來為用戶未安裝導(dǎo)航軟件時(shí)打開瀏覽器所使用url
        plus.nativeUI.actionSheet({ //選擇菜單
            title: "選擇地圖應(yīng)用",
            cancel: "取消",
            buttons: [{title: "高德地圖"}] // 可選的地圖類型
        }, (e)=> {
                // 判斷用戶選擇的地圖
            switch (e.index) {
                //下面是拼接url,不同系統(tǒng)以及不同地圖都有不同的拼接字段
                case 1:
                    // 安卓
                    if(plus.os.name == "Android") {
                        url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
                    }else {
                        url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
                    }
                    webUrl = `https://uri.amap.com/marker?position=${longitude},${latitude}&name=${name}&src=mypage&coordinate=gaode`
                    break;
            }
                // 如果選中
            if (url != "") {
                url = encodeURI(url);
                // 打開 app 導(dǎo)航 
                plus.runtime.openURL(url, (err)=>{ // 失敗回到
                    // 如果失敗則說明未安裝 直接 打開網(wǎng)頁版進(jìn)行導(dǎo)航
                    // 畢竟用戶可能沒有安裝app但一定安裝的有瀏覽器
                    plus.runtime.openURL(webUrl);
                });
            }
    })
}

這就是我導(dǎo)航彈窗實(shí)現(xiàn)的邏輯了, 這里我僅僅只是用了高德地圖的選項(xiàng),大家可以根據(jù)需要增加相應(yīng)地圖app,其他常見的我放在下方了。

騰訊

app url

let appUrl = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=${騰訊地圖key}`

web url

let webUrl = `https://apis.map.qq.com/uri/v1/marker?marker=coord:經(jīng)度,緯度;title:名稱;addr:地址&referer=myapp`

百度

app url

let appUrl = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`

web url

let webUrl = `http://api.map.baidu.com/marker?location=${latitude},${longitude}&title=${name}&content=${content}&output=html&src=webapp.baidu.openAPIdemo`

推薦:《uniapp教程

The above is the detailed content of Use uniapp to develop a simple map navigation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to develop uni-app in VSCode? (Tutorial sharing) How to develop uni-app in VSCode? (Tutorial sharing) May 13, 2022 pm 08:11 PM

How to develop uni-app in VSCode? The following article will share with you a tutorial on developing uni-app in VSCode. This may be the best and most detailed tutorial. Come and take a look!

Use uniapp to develop a simple map navigation Use uniapp to develop a simple map navigation Jun 09, 2022 pm 07:46 PM

How to use uniapp to develop a simple map navigation? This article will provide you with an idea for making a simple map. I hope it will be helpful to you!

How to encapsulate uni-app vue3 interface request How to encapsulate uni-app vue3 interface request May 11, 2023 pm 07:28 PM

uni-app interface, global method encapsulation 1. Create an api file in the root directory, create api.js, baseUrl.js and http.js files in the api folder 2.baseUrl.js file code exportdefault"https://XXXX .test03.qcw800.com/api/"3.http.js file code exportfunctionhttps(opts,data){lethttpDefaultOpts={url:opts.url,data:data,method:opts.method

Take you step by step to develop a uni-app calendar plug-in (and publish it) Take you step by step to develop a uni-app calendar plug-in (and publish it) Jun 30, 2022 pm 08:13 PM

This article will guide you step by step in developing a uni-app calendar plug-in, and introduce how the next calendar plug-in is developed from development to release. I hope it will be helpful to you!

Let's talk about how to use uniapp to develop a snake game! Let's talk about how to use uniapp to develop a snake game! May 20, 2022 pm 07:56 PM

How to use uniapp to develop a snake game? The following article will take you step by step to implement the Snake game in uniapp. I hope it will be helpful to you!

Detailed example of how uniapp implements phone recording function (with code) Detailed example of how uniapp implements phone recording function (with code) Jan 05, 2023 pm 04:41 PM

This article brings you relevant knowledge about uniapp. It mainly introduces how to use uniapp to make calls and synchronize recording. Friends who are interested should take a look at it. I hope it will be helpful to everyone.

Examples to explain how uniapp implements the all-select function of multi-select boxes Examples to explain how uniapp implements the all-select function of multi-select boxes Jun 22, 2022 am 11:57 AM

This article brings you relevant knowledge about uniapp, which mainly organizes the related issues of implementing the select-all function of the multi-select box. The reason why the select-all function cannot be implemented is that when the checked field of the checkbox is dynamically modified, the status on the interface can Real-time changes, but the change event of checkbox-group cannot be triggered. Let's take a look at it. I hope it will be helpful to everyone.

Let's talk about uniapp's scroll-view drop-down loading Let's talk about uniapp's scroll-view drop-down loading Jul 14, 2022 pm 09:07 PM

How does uniapp implement scroll-view drop-down loading? The following article talks about the drop-down loading of the uniapp WeChat applet scroll-view. I hope it will be helpful to everyone!

See all articles

TypeRequired