特效详情:

vue手机移动端城市定位和选择代码,默认获取我的当前所在城市定位,可自定义更换选择城市,带城市列表首字母导航功能。请在手机端查看演示,电脑端无法选择。

js代码

var app = new Vue({

el: '#app',

data: {

origin: 'http://192.168.99.205:800',

captchaBoxShow: false,

test: '测试',

countTime: 0,

countTimer: null,

time: 60,

location: '定位中',

submit: {

sms_captcha  : '',

captcha      : '',

area_code    : '',

_token       : '',

},

map: new AMap.Map("container", {

resizeEnable: true,

//city: citycode,

zoom: 17, //地图显示的缩放级别

keyboardEnable: false,

citylimit: true,

resizeEnable: true

}),

cityWrapper: document.querySelector('.city-wrapper-hook'),

cityScroller: document.querySelector('.scroller-hook'),

cities: document.querySelector('.cities-hook'),

shortcut: document.querySelector('.shortcut-hook'),

shortcutList: [],

cityData: cityData,// 数据源

scroll: null,

anchorMap: {},

touch: {},

toastShow: false,

isShowCitys: false,

toastText: '',

},

methods: {

toast (str) {

let v = this

v.toastText = str

v.toastShow = true

setTimeout(function(){

v.toastShow = false

}, 1500)

},

chooseCity (city) {

let v = this

v.countTime = 0

v.countTimer = setInterval(function(e){v.countTime ++},1)

},

touchUp (item) {

let v = this

clearInterval(v.countTimer)

if (v.countTime < 30) {

this.isShowCitys = false

this.location = item.name

this.submit.area_code = item.code

}

},

selectLocation () {

let v = this

this.isShowCitys = true

this.$nextTick(function() {

this.initCities()

})

},

geocoder_CallBack: function (data) {

let v = this

var adcode3     = data.regeocode.addressComponent.adcode;

var address     = data.regeocode.formattedAddress; //返回地址描述

var csqy        = data.regeocode.addressComponent.district; //地区

var csadcode    = data.regeocode.addressComponent.adcode; //区域编码

this.submit.area_code = csadcode

var citycode2   = csadcode.substr(0, 4) + "00"; //省份编码

var codes       = adcode3.substr(0, 4) + "00";

var citys2      = data.regeocode.addressComponent.city;

var poiArr      = data.regeocode.pois; //坐标

var resultCount = poiArr.length;

v.location      = csqy

var dz          = data.regeocode.formattedAddress;

var lng         = data.regeocode.roads[0].location.lng;

var lat         = data.regeocode.roads[0].location.lat;

},

zddw: function () {

//初始定位

let v = this

v.map.plugin('AMap.Geolocation', function() {

geolocation = new AMap.Geolocation({

enableHighAccuracy: true, //是否使用高精度定位,默认:true

//timeout: 10000, //超过10秒后停止定位,默认:无穷大

buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)

zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false

noIpLocate: 0, //IP定位,0-3,0都可以使用

noGeoLocation: 0, //浏览器定位 0-3,

showCircle: false, //去除定位蓝圈

buttonPosition: 'RT',

extensions: 'all'

});

v.map.addControl(geolocation);

geolocation.getCurrentPosition();

AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息

AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息

});

//解析定位结果

function onComplete(data) {

var str = [];

str.push(data.position.lng);

str.push(data.position.lat);

var geocoder = new AMap.Geocoder({

radius: 1000,

extensions: "all"

});

geocoder.getAddress(str, function(status, result) {

if (status === 'complete' && result.info === 'OK') {

v.geocoder_CallBack(result);

}

});

}

// 解析定位错误信息

function onError(data) {

alert('定位失败,请手动选择所在区域');

}

},

initCities: function () {

let v = this

let y = 0;

var titleHeight = 28

var itemHeight = 44

v.cityData.forEach(function(e){

let name = e.name.substr(0, 1)

let len = e.cities.length

v.anchorMap[name] = y

y -= titleHeight + len * itemHeight

})

v.shortcut = document.querySelector('.shortcut-hook')

v.cityWrapper = document.querySelector('.city-wrapper-hook')

v.shortcut.style.top = (v.cityWrapper.clientHeight - v.shortcut.clientHeight) / 2 + 'px';

v.scroll = new window.BScroll(v.cityWrapper, {

probeType: 3

})

// console.log(v.scroll, 'v.scroll')

// v.scroll.hasVerticalScroll = true

// v.scroll.wrapperHeight = $('body').height()

v.scroll.scrollTo(0, 0);

},

touchIndex: function (e) {

// console.log(e, 'e')

let v = this

let anchor = e.target.getAttribute('data-anchor')

// console.log(anchor ,'anchor')

let firstTouch = e.touches[0]

v.touch.y1 = firstTouch.pageY

v.touch.anchor = anchor

v.scrollTo(anchor)

},

scrollTo: function (anchor) {

let v = this

v.cityScroller = document.querySelector('.scroller-hook')

var maxScrollY = v.cityWrapper.clientHeight - v.cityScroller.clientHeight

var y = Math.min(0, Math.max(maxScrollY, v.anchorMap[anchor]))

if (typeof y !== 'undefined') {

v.scroll.scrollTo(0, y);

}

},

},

mounted: function () {

let v = this

this.zddw()

v.initCities()

},

})

vue移动端获取定位_vue手机移动端城市定位和选择代码相关推荐

  1. 【练习】jsonP的实际应用,移动端web,京东手机移动端(开头)

    1.百度地图开放平台jsonP的实际应用 http://lbsyun.baidu.com/index.php?title=webapi/direction-api-v2 找到一个端口,把ak改成自己的 ...

  2. gnss单频软件接收机应用与编程_GNSS/GPS RTK定位 (手机,无人车定位,无人驾驶,因子图优化)...

    Global navigation satellite system (GNSS)是手机或者无人车定位中的关键一个部分.GNSS是当前主要的可以提供绝对定位信息的一种信息来源.无人车的基于地图匹配定位 ...

  3. vue+echarts 后台获取数据_vue+element+echarts 响应式后台管理系统,了解一下?

    寒假结束了,趁着寒假,自己玩了一下element和echarts去实现了一个简单的后台管理系统. 项目比较简单,十分适合入门,涉及到了轮播图,表格,表单,echarts柱形图和折线图,以及网页的响应式 ...

  4. 怎样关闭qq位置定位服务器,手机qq怎么关闭定位

    设置方法:首先打开手机QQ,点击"动态"--"附近",点击"附近的人"右侧的漏斗图标,点击"清除位置信息并退出"即可完成 ...

  5. 移动端web设计尺寸_手机移动端网页按钮设计尺寸及间距规范

    网页版面上的字体大小有讲究,而网站的按钮的尺寸及按钮之间的间距标准非常有细节规范. 序幕 - 点击,再点击,重复点击!用户是否能够以高触摸精度点击您的移动按钮,又或者他们是错过了按钮的目标?在责怪用户 ...

  6. 华为手机上高德sdk定位不准

    问题 在华为手机上测试高德sdk时,发现在切换城市或默认定位当前城市时,总是返回默认定位位置北京. 原因 由于华为的芯片是自主研发,导致和高德sdk的接口不兼容.因此无法准确定位. 高德sdk定位的逻 ...

  7. h5获取安卓定位_H5 移动端获取当前位置

    3种方法: 1.H5自带的方法,获取经纬度 2.通过地图提供的JS.获取位置 3.通过微信的API(这个需要公众号 / 小程序) 1.通过H5自带的获取经纬度的方法 优点: 需要引用的资源较少,H5自 ...

  8. Dynamics 365Online 如何在手机app端获取当前位置的GPS信息

    众所周知365自带的手机app端是很弱的,但再弱还是聊胜于无,至少还是可以用的,而且功能也在不断的加强中. 本篇要分享的是如果使用SDK中开放的API,在手机端app中调用GPS信息,代码很简单 va ...

  9. h5获取android手机版本,Vue.js怎么获取手机系统型号、版本、浏览器类型

    Vue.js怎么获取手机系统型号.版本.浏览器类型 发布时间:2020-07-28 11:22:33 来源:亿速云 阅读:161 作者:小猪 这篇文章主要为大家展示了Vue.js怎么获取手机系统型号. ...

最新文章

  1. Python常用库使用笔记
  2. Ubuntu16.04 -- 后台进程Nohup
  3. nodemanager不能正常关闭_Java虚拟机关闭钩子(Shutdown hook)
  4. linux 用mutex定义一个linkedlist,一个高性能无锁非阻塞链表队列
  5. linux——线程(2)
  6. 中国银行业协会首席信息官高峰:银行函证区块链服务平台具备六大优势
  7. ruby nokogiri 数据抓取
  8. 玩转windows内置linux子系统_1.安装
  9. MFC使用自带的MSXML6.dll解析xml(开发环境vc2010)
  10. python中字符串以什么结尾_python判断字符串以什么结尾的实例方法
  11. volo拉丁语_你为什么学习拉丁语?
  12. chrome浏览器无法安装crx插件的解决方法(以翻译插件为例)
  13. 服务器有哪些品牌,各品牌服务器之间性价比对比!
  14. geany配置python_Python 04 Geany的安装和配置
  15. 腾讯安全月报丨发布安心计划、携手上汽共建安全实验室、多项产品入选国际研报……
  16. QueryWrapper用法集合
  17. 华为敏捷项目管理实践分享
  18. 38款 流媒体服务器开源软件
  19. 理想汽车 x StarRocks:为 Hive 数据查询插上极速之翼
  20. oracle 紧急情况检查应急预案 doc,专项检查应急预案.doc

热门文章

  1. c语言程序设计实训教材,清华大学出版社-图书详情-《C语言程序设计实训》
  2. VC6应用程序正常初始化(0xc0150002)失败的终极解决方案
  3. [小北De编程手记] [Lesson 02] AutoFramework构建 之 Page Objects - 设计模式
  4. [Leetcode 每日精选](本周主题-并查集) 面试题 17.07. 婴儿名字
  5. Unity实战篇:使用图片制作自己的艺术字
  6. Mcafee email gateway 全新安装(一)
  7. Unifi(Ubnt)如何实现办公室网络搭建和VLAN划分
  8. 读书笔记-企业护城河的瓦解
  9. 交易平台何时拥有定价权:初探背后的经济学原理
  10. 2021年中国光伏玻璃行业现状及发展趋势分析,厚度较低的光伏玻璃将是未来趋势「图」