非微信浏览器定位
{if $_W['container'] != 'wechat'}<script src="https://mapapi.qq.com/web/mapComponents/geoLocation/v/geolocation.min.js"></script>
<script>
var geolocation = new qq.maps.Geolocation("{$system['qqmapkey']}", "myapp");
{if empty($_GPC['located']) && $_GPC['do'] != 'city'}
$.confirm('为给您提供更好的服务,请授权我们获取您的位置信息', '用户位置请求', function() {
geolocation.getLocation(showPosition, showErr, {timeout: 8000});
});
function showPosition(position) {
//console.log(position);
/**
* position.lat//纬度
* position.lng//经度
* position.adcode//行政区划代码
* position.addr//定位地址
* position.nation//国家
* position.province//省份
* position.city//城市
* position.district//地区
*/
//定位请求
$.post("{php echo $this->createMobileUrl('store', array('op'=>'locate'))}", {lat: position.lat, lng: position.lng}, function(res) {
var data = $.parseJSON(res);
if (data.message.errno < 0) {
$.alert(data.message.message, 'text');
return;
} else {
$.toast(data.message.message, 'text');
window.location.reload();
}
});
}
function showErr() {
console.log('定位失败');
}
{/if}
</script>
{/if}
页:
[1]