当前位置:网站首页>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~
边栏推荐
- MySQL data advanced
- 2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。
- 415 binary tree (144. preorder traversal of binary tree, 145. postorder traversal of binary tree, 94. inorder traversal of binary tree)
- leetCode-1089: 复写零
- 植物生长h5动画js特效
- El table Click to add row style
- Observer mode
- 解决Deprecated: Methods with the same name as their class will not be constructors in报错方案
- tf.contrib.layers.batch_norm
- JS proxy mode
猜你喜欢
随机推荐
小程序 rich-text中图片点击放大与自适应大小问题
numpy.logical_and()
机器学习——主成分分析(PCA)
How to standardize data center infrastructure management process
Phpstrom code formatting settings
Desktop software development framework reward
416-二叉树(前中后序遍历—迭代法)
Leetcode - 498: traversée diagonale
canvas无限扫描js特效代码
web网站开发,图片懒加载
Go language development environment setup +goland configuration under the latest Windows
Basic operations on binary tree
自定义kindeditor编辑器的工具栏,items即去除不必要的工具栏或者保留部分工具栏
Yolov6: the fast and accurate target detection framework is open source
Cicflowmeter source code analysis and modification to meet requirements
uniapp实现点击拨打电话功能
为什么 JSX 语法这么香?
Leetcode interview question 01.05: primary editing
Why is JSX syntax so popular?
leetCode-929: 独特的电子邮件地址