通过腾讯地图api获取用户位置限制在指定位置区域

编程入门 行业动态 更新时间:2024-10-24 06:34:09

通过腾讯地图api获取用户<a href=https://www.elefans.com/category/jswz/34/1771147.html style=位置限制在指定位置区域"/>

通过腾讯地图api获取用户位置限制在指定位置区域

<!--在微信中获取用户位置-->
<script src=".0.0.js"></script><script charset="utf-8" src="=2.exp&key=3FVBZ-FZ2KW-E7CR4-ROZRS-B7TNQ-C7BSI"></script><script type="text/javascript">var map;var markerE;var wd = "", jd = "", fw = "", address = "", isCompany = 0;var init = function () {map = new qq.maps.Map(document.getElementById("container"), {center: new qq.maps.LatLng(30.602239286171868, 114.51272616386414),zoom: 15});var polygon = new qq.maps.Polygon({map: map,path: path,strokeColor: new qq.maps.Color(0, 0, 0, 0.5),fillColor: qq.maps.Color.fromHex("#000000", 0.5)});}var path = [new qq.maps.LatLng(30.602165333622294, 114.51280663013458),new qq.maps.LatLng(30.601347229791023, 114.51272616386414),new qq.maps.LatLng(30.601236299928177, 114.51398680210114),new qq.maps.LatLng(30.60208213693682, 114.51407799720764)];function isInsidePolygon(pt, poly) {for (var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)((poly[i].lat <= pt.lat && pt.lat < poly[j].lat) || (poly[j].lat <= pt.lat && pt.lat < poly[i].lat)) &&(pt.lng < (poly[j].lng - poly[i].lng) * (pt.lat - poly[i].lat) / (poly[j].lat - poly[i].lat) + poly[i].lng) &&(c = !c);return c;}var dksubmit = function () {$('#dialog1').hide();if (address == "") {$("#dialog2").show().find("#msg").text("未获取到地址,请先定位");} else {$.post("url", { wd: wd, jd: jd, fw: fw, add: address, isCompany: isCompany }, function (res) {if (res == "true") {$("#dialog2").show().find("#msg").text("在规定位置");} else {$("#dialog2").show().find("#msg").text(res);}});}}$(document).ready(function () {$(".weui_loading_toast").show();wx.ready(function () {$(".dw").click();});wx.error(function (res) {var msg = "";for (var i in res) {msg += i + ":" + res[i] + "|";}alert("ERROR:" + msg);});wx.config(@(new HtmlString(ViewBag.sign)));init();$(".dw").click(function () {wx.getLocation({type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function (res) {var loc = new qq.maps.LatLng(res.latitude, res.longitude);map.setCenter(loc);if (markerE) {markerE.setPosition(loc);} else {markerE = new qq.maps.Marker({position: loc,map: map});}$("#zb").text(res.latitude + "," + res.longitude);var geocoder = new qq.maps.Geocoder({complete: function (result) {$("#dz").text(result.detail.address);address = result.detail.address;}});var coord = new qq.maps.LatLng(res.latitude, res.longitude);geocoder.getAddress(coord);wd = res.latitude;jd = res.longitude;if (res.accuracy != undefined) {fw = res.accuracy;} else {fw = 0;}if (isInsidePolygon(loc, path)) {$("#yx").text("有效位置");isCompany = 1;}else {isCompany = 0;$("#yx").text("无效位置");}$(".weui_loading_toast").hide();}});});});</script>

 

转载于:.html

更多推荐

通过腾讯地图api获取用户位置限制在指定位置区域

本文发布于:2024-02-10 16:33:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1676242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   腾讯   区域   地图   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!