<!--在微信中獲取用戶位置-->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script charset="utf-8" src="http://map.qq.com/api/js?v=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>