微信小程序 开发MAP(地图)实例详解
在创建MAP(地图)前,请各位小伙伴们认真的去了解微信小程序开发的说明。
https://mp.weixin.qq.com/debug/wxadoc/dev/component/map.html#map
了解完MAP(地图)里的属性之后,接下来我们就来创建一个简单的MAP(地图)控件。
第一步:肯定是创建项目、起项目名、项目地址
PS:我这里以index的文件为名
第二步:我们来写 index.wxml 文件的代码
WXML文件代码:
<map id="map4select" longitude="{{longitude}}" latitude="{{latitude}}" markers="{{markers}}" scale="20" style="width:{{map_width}}px;height:{{map_height}}px" bindregionchange="regionchange" controls="{{controls}}"> </map>
WXML文件的代码写好之后,就要来进行第三步了。
第三步:写 index.js 文件的代码
var app = getApp() Page({ data: { map_width: 380 , map_height: 380 } //show current position , onLoad: function (options) { console.log(options.schedule_id); var that = this; // 获取定位,并把位置标示出来 that.setData({ longitude: 113.324520 , latitude: 23.099994 , markers: [ { id: 0 , iconPath: "../imgs/ic_position.png" , longitude: 113.324520 , latitude: 23.099994 , width: 30 , height: 30 } ] }) //set the width and height // 动态设置map的宽和高 wx.getSystemInfo({ success: function (res) { console.log(res.windowWidth); that.setData({ map_width: res.windowWidth , map_height: res.windowWidth , controls: [{ id: 1, iconPath: '../imgs/ic_location.png', position: { left: res.windowWidth / 2 - 8 , top: res.windowWidth / 2 - 16 , width: 30, height: 30 }, clickable: true }] }) } }) } //获取中间点的经纬度,并mark出来 , getLngLat: function () { var that = this; this.mapCtx = wx.createMapContext("map4select"); this.mapCtx.getCenterLocation({ success: function (res) { that.setData({ longitude: 113.324520 , latitude: 23.099994 , markers: [ { id: 0 , iconPath: "../imgs/ic_position.png" , longitude: 113.324520 , latitude: 23.099994 , width: 30 , height: 30 } ] }) } }) } , regionchange(e) { // 地图发生变化的时候,获取中间点,也就是用户选择的位置 if (e.type == 'end') { this.getLngLat() } } , markertap(e) { console.log(e) } })
index.js 和 index.wxml 两个文件的代码已经写好,那么我们就来页面上看看效果。
PS:“../imgs/ic_position.png” 和 “../imgs/ic_location.png” 是我在项目里创建的一个名叫imgs文件夹里面的两个定位小图标,各位小伙伴们可以根据自己的需求改换小图标,只需要把小图标放进imgs文件夹里面,小图标的路径引用正确就可以显示出来。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年09月24日
2024年09月24日
- 国风大师纯音系列《古筝仙子 常静演奏 十指弹一》1CD[FLAC][919MB]
- DasKapital-OneMustHaveChaosInsidetoGiveBirthtoaDancingStar(2024)[24-44.1]WAV
- 王菲.1999-《只爱陌生人》日本东芝版[低速原抓WAV+CUE]
- 张小英1987-金奖金曲第一集[新加坡版][WAV+CUE]
- 鹿晗.2015-重启【海蝶】【FLAC分轨】
- 张芸京.2012-小女孩【金牌大风】【WAV+CUE】
- 余天.2002-雄狮魅力金曲2CD(南方金点系列)【南方】【WAV+CUE】
- 银霞.1982-《结·SAYYESMYBOY》台湾复刻版[WAV+CUE]
- 梁汉文1993-火热动感[引进版][WAV+CUE]
- 梁汉文2008-EDMONDHITS48[香港]3CD[WAV+CUE]
- 国风大师纯音系列《童丽-[渭城曲]》1CD[WAV分轨][593.5MB]
- 国风大师纯音系列《许菱子《烧筝2》古筝曲集》1CD[WAV分轨][1.3GB]
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】