<?php
$appid="**************";
$secret="**********************";
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
$output = gettoken($url);
$token=(array)json_decode($output);
$access = $token['access_token'];
$ticket0 = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access."&type=jsapi";
$ticket1 = gettoken($ticket0);
$ticket2=(array)json_decode($ticket1);
$ticket = $ticket2['ticket'];
$noncestr="Wm3WZYTPz0wzccnW";
$timestamp=time();
$url="http://xz155559.applinzi.com/location.php";
$string = "jsapi_ticket=".$ticket."&noncestr=".$noncestr."×tamp=".$timestamp."&url=".$url."";
$signature = sha1($string);
function gettoken($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 safari/537.22");
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取当前位置</title>
</head>
<body>
<div></div>
</body>
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>
wx.config({
debug: true,
appId: "**************",
timestamp: $timestamp,
nonceStr: $noncestr,
signature: $signature,
jsApiList: [
// 所有要调用的 API 都要加到这个列表中
'getLocation'
]
});
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
complete: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
}
});
</script>
</html>
先感谢各位提供回答的朋友,这个问题困扰我太久,请你们不吝赐教,你的一句话可能就是答案。谢谢