当前位置:网站首页>Uniapp develops a wechat applet to display the map function, and click it to open Gaode or Tencent map.
Uniapp develops a wechat applet to display the map function, and click it to open Gaode or Tencent map.
2022-06-24 10:16:00 【Ma Xiaotiao coding】
When I first came across the map , It's complicated . Think about whether you need to quote Gaode or Baidu map api And so on. .
There's no need to , Use uniapp Own method uni.openLocation that will do .
Don't talk much , Complete code 、 notes 、 And the problems encountered in the development are as follows :
1、uniapp After packaged into wechat applet — To configure app.json file
// Development process , Need to be in unpackage>>dist>>dev>>mp-weixin>>app.json Add the following configuration to
"permission": {
"scope.userLocation": {
"desc": " Your location information will be used to show the effect of the applet location interface "
}
}
// stay manifest.json Configure... In the source view of : To configure appid And geographical location
"mp-weixin": {
/* Applet specific relevance */
"appid": "", // Need configuration appid
"setting": {
"urlCheck": false
},
"usingComponents": true,
"permission": {
"scope.userLocation": {
"desc": " Your location information will be used to show the effect of the applet location interface "
}
}
}
2. Page specific code :
<template>
<view class="">
<view class="ditu">
<map style="width:100%;height:100%;" :latitude="latitude" :longitude="longitude" :scale="scale" :markers="marker" @markertap="toMap()">
<!-- There is a problem of stepping on the pit 1: @markertap Is when you click the marked point on the map Trigger open map . @tap When you click on the whole map Trigger open map . -->
</map>
</view>
</view>
</template>
<script> export default {
data() {
return {
latitude: '', // latitude longitude: '', // longitude marker: [{
id: 0, latitude: '', // latitude longitude: '', // longitude // title: ' Shandong XX Co., Ltd ', // Mark the roll alpha: 1, // transparency }], scale: 14, // Zoom the map address: '' } }, methods: {
// Click on the mark on the map , Open the built-in map of your phone toMap() {
console.log(' Click on the map ') uni.openLocation({
latitude: Number(this.latitude), // Latitude to go to - Address longitude: Number(this.longitude), // Longitude to go - Address address: this.address, // The specific address to go // Here is the problem of stepping on the pit 2: //latitude and longitude It must be number type . // Therefore, you need to use Number Convert it . }) }, } } </script>
<style scoped> .ditu {
width: 100%; height: 565rpx; } </style>
3. Development complete ~ As shown in the figure below :




4. Two questions about stepping on the pit :
① Click where to trigger the map ?@markertap Is when you click the marked point on the map Trigger open map .@tap When you click on the whole map Trigger open map .

②uni.openLocation No response when clicking to open the map ?
Note the data type of longitude and latitude : Use Number

ending~
边栏推荐
猜你喜欢

Groovy obtains Jenkins credentials through withcredentials

How to manage massive network infrastructure?

411 stack and queue (20. valid parentheses, 1047. delete all adjacent duplicates in the string, 150. inverse Polish expression evaluation, 239. sliding window maximum, 347. the first k high-frequency

4.分类管理业务开发

线程池的执行流程

p5.js千纸鹤动画背景js特效

小程序学习之获取用户信息(getUserProfile and getUserInfo)

百度网盘下载一直请求中问题解决

Three ways to use applicationcontextinitializer

Phpstrom code formatting settings
随机推荐
Arbre binaire partie 1
线程的 sleep() 方法与 wait() 方法的区别
TP5 using post to receive array data times variable type error: solution to array error
Juul, the American e-cigarette giant, suffered a disaster, and all products were forced off the shelves
Indexeddb local storage, homepage optimization
涂鸦智能携多款重磅智能照明解决方案,亮相2022美国国际照明展
415 binary tree (144. preorder traversal of binary tree, 145. postorder traversal of binary tree, 94. inorder traversal of binary tree)
学习使用php对字符串中的特殊符号进行过滤的方法
包装类型与基本类型的区别
SQL sever基本数据类型详解
How large and medium-sized enterprises build their own monitoring system
web网站开发,图片懒加载
canvas掉落的小球重力js特效动画
Yolov6: the fast and accurate target detection framework is open source
Array seamless scrolling demo
SQL statistics of users logged in for N consecutive days
leetCode-1051: 高度检查器
植物生长h5动画js特效
5.菜品管理业务开发
分布式 | 如何与 DBLE 进行“秘密通话”