随着交通经济的发展,人们的活动区域越来越大,不认识路,找不到目的地的情况也屡有发生,地图导航的功能可以帮用户导航到目的地。
https://lbs.amap.com/
,该频道提供各种开发文档,参考手册,功能演示,和工具资源,供开发者下载使用。目的地
和起始地
的坐标,然后再根据两地的坐标来进行导航。“鼠标拾取地图坐标”
功能来获得目的地的坐标,该功能的地址为:https://lbs.amap.com/api/javascript-api/example/map/click-to-get-lnglat/
公交线路导航接口:
http://mo.amap.com/?from=".$object->Location_X.",".$object->Location_Y."(".$object->Label.")&to=".$Pondbay['latitude'].",".$Pondbay['longitude']."(".$Pondbay['name'].")&type=1&opt=0&dev=1")
驾车线路导航接口:
http://mo.amap.com/?from=".$object->Location_X.",".$object->Location_Y."(".$object->Label.")&to=".$Pondbay['latitude'].",".$Pondbay['longitude']."(".$Pondbay['name'].")&type=0&opt=1&dev=1"
index.php完整代码如下:
/*
CopyRight 2018-
All Rights Reserved
*/
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (!isset($_GET['echostr'])) {
$wechatObj->responseMsg();
}else{
$wechatObj->valid();
}
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
if($tmpStr == $signature){
return true;
}else{
return false;
}
}
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
$this->logger("R ".$postStr);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$RX_TYPE = trim($postObj->MsgType);
switch ($RX_TYPE)
{
case "event":
$result = $this->receiveEvent($postObj);
break;
case "text":
$result = $this->receiveText($postObj);
break;
case "location":
$result = $this->receiveLocation($postObj);
break;
default:
$result = "unknow msg type: ".$RX_TYPE;
break;
}
$this->logger("T ".$result);
echo $result;
}else {
echo "";
exit;
}
}
private function receiveEvent($object)
{
$content = "";
switch ($object->Event)
{
case "subscribe":
$content = "欢迎关注 德强1012 ";
$content .= isset($object->EventKey)?("\n来自二维码场景 ".$object->EventKey):"";
break;
case "unsubscribe":
$content = "取消关注";
break;
}
$result = $this->transmitText($object, $content);
return $result;
}
private function receiveText($object)
{
$keyword = trim($object->Content);
$content = date("Y-m-d H:i:s",time());
$result = $this->transmitText($object, $content);
return $result;
}
private function receiveLocation($object)
{
$Pondbay = array("name" => "方倍工作室", "latitude" => "22.539394", "longitude" => "113.956246");
$content[] = array("Title" =>"高德地图为您导航",
"Description" =>"",
"PicUrl" =>"",
"Url" =>"");
$content[] = array("Title" =>"点击图片查看公交线路导航",
"Description" =>"",
"PicUrl" =>"http://h.hiphotos.bdimg.com/wisegame/pic/item/1fd98d1001e9390186c2c97479ec54e737d196bc.jpg",
"Url" =>"http://mo.amap.com/?from=".$object->Location_X.",".$object->Location_Y."(".$object->Label.")&to=".$Pondbay['latitude'].",".$Pondbay['longitude']."(".$Pondbay['name'].")&type=1&opt=0&dev=1");
$content[] = array("Title" =>"点击图片查看驾车线路导航",
"Description" =>"",
"PicUrl" =>"http://b.hiphotos.bdimg.com/wisegame/pic/item/eeb1cb1349540923f48a42079058d109b2de49e3.jpg",
"Url" =>"http://mo.amap.com/?from=".$object->Location_X.",".$object->Location_Y."(".$object->Label.")&to=".$Pondbay['latitude'].",".$Pondbay['longitude']."(".$Pondbay['name'].")&type=0&opt=1&dev=1");
$result = $this->transmitNews($object, $content);
return $result;
}
private function transmitText($object, $content)
{
$textTpl = "
%s
";
$result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content);
return $result;
}
private function transmitNews($object, $arr_item)
{
if(!is_array($arr_item))
return;
$itemTpl = " -
";
$item_str = "";
foreach ($arr_item as $item)
$item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);
$newsTpl = "
%s
%s
$item_str
";
$result = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($arr_item));
return $result;
}
private function logger($log_content)
{
if(isset($_SERVER['HTTP_APPNAME'])){ //SAE
sae_set_display_errors(false);
sae_debug($log_content);
sae_set_display_errors(true);
}else if($_SERVER['REMOTE_ADDR'] != "127.0.0.1"){ //LOCAL
$max_size = 10000;
$log_filename = "log.xml";
if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}
file_put_contents($log_filename, date('H:i:s')." ".$log_content."\r\n", FILE_APPEND);
}
}
}
?>