车联网API——位置、距离
来源:互联网 发布:java 代码 编辑:程序博客网 时间:2024/05/04 11:48
车联网API——位置、距离
车联网接口
反Geocoding:http://lbsyun.baidu.com/index.php?title=car/api/anti-geocoding
测距:http://lbsyun.baidu.com/index.php?title=car/api/distance
wx_sample.php
...... //responseMsg整理 public function responseMsg(){ //get post data,May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if(!empty($postStr)){//如果用户端发来的文本内容不为空 $postObj = simplexml_load_string($postStr,'SimpleXMLElement',LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->toUserName; $type = $postObj->MsgType; $latitude = $postObj->Location_X; $longitude = $postObj->Location_Y: $time = time(); $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> <FuncFlag>0</FuncFlag> </xml>"; switch ($type) { case 'image': $contentStr = "你的图片很棒!"; break; case 'location': //位置 //反Geocoding接口 $geourl = "http://api.map.baidu.com/telematics/v2/reverseGeocoding?location={$longitude},{$latitude}&ak=la3cde429f38434f1811a75e1a90310c"; //读取文件 $apistr = file_get_contents($geourl); //xml解析 $apiobj = simplexml_load_string($apistr); $addstr = $apiobj->results->address; //逐级解析 $contentStr = "我知道你在{$addstr}附近"; //测距 //测距api $geourl = "http://api.map.baidu.com/telematics/v2/distance?waypoints=116.681889,23.355164;{$longitude},{$latitude}&ak=1a3cde429f38434f1811a75e1a90310c"; $apistr = file_get_contents($geourl); $apiobj = simplexml_load_string($apistr); $distanceobj = $apiobj->results->distance; //强制转换公里数 //转为int $distanceint = intval($distanceobj); //转为公里 $diskmint = distanceint/1000; if($diskmint<5){ $contentStr = "你离公司还有{$diskmint}公里远,我们可以免费送货上门"; }else{ $contentStr = "你离公司还有{$diskmint}公里远,我们不能送货上门"; } //多距离比较 //第一个店铺的距离 $geourl1 = "http://api.map.baidu.com/telematics/v2/distqance?waypoints=116.681837,23.353299;{$longitude},{$latitude}&ak=1a3cde429f38434f1811a75e1a90310c"; $apistr1 = file_get_contents($geourl1); $apiobj1 = simplexml_load_string($apistr1); $distanceobj1 = $apiobj1->results->distance; $distanceint1 = intval($distanceobj1); //第二个店铺的距离 $geourl2 = "http://api.map.baidu.com/telematics/v2/distqance?waypoints=116.756091,23.46596;{$longitude},{$latitude}&ak=1a3cde429f38434f1811a75e1a90310c"; $apistr2 = file_get_contents($geourl2); $apiobj2 = simplexml_load_string($apistr2); $distanceobj2 = $apiobj2->results->distance; $distanceint2 = intval($distanceobj2); //第三个店铺的距离 $geourl3 = "http://api.map.baidu.com/telematics/v2/distqance?waypoints=116.372831,23.549993;{$longitude},{$latitude}&ak=1a3cde429f38434f1811a75e1a90310c"; $apistr3 = file_get_contents($geourl3); $apiobj3 = simplexml_load_string($apistr3); $distanceobj3 = $apiobj3->results->distance; $distanceint3 = intval($distanceobj3); //最近的店铺距离 $mindistanceint = min($distanceint1,$distanceint2,$distanceint3); if($mindistanceint == $distanceint1){ $contentStr = "离你最近的店铺有{$mindistanceint}米远,位置是1号路"; }elseif($mindistanceint == $distanceint2){ $contentStr = "离你最近的店铺有{$mindistanceint}米远,位置是2号路"; }else{ $contentStr = "离你最近的店铺有{$mindistanceint}米远,位置是3号路"; } $contentStr = "你离公司还有『$distanceobj}米远"; break; case 'link': $contentStr = "这是个link"; break; default: $contentStr = "此项功能尚未开发"; } $msgType = "text"; $resultStr = sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr); echo $resultStr; }else{//如果用户端发来的文本内容为空 echo ""; exit; } }......
0 0
- 车联网API——位置、距离
- 百度车联网API
- Android手机平台wifi信息保存位置以及联网API
- 【matlab】物联网专题——Internet of Things : 物联网和你只有一个MATLAB的距离!
- 调用 车联网API 一些收获
- 页面距离位置整理
- Javascript——百度地图API——显示位置
- android API——LocationManager获取位置信息
- 百度定位与车联网API实现天气预报
- CNTK API文档翻译(11)——使用LSTM预测时间序列数据(物联网数据)
- Android 实现联网——在线程中联网
- Android 实现联网——在线程中联网
- 【百度地图API】建立全国银行位置查询系统(一)——如何创建地图
- Android位置服务和Google地图API初解——名词解释
- 【百度地图API】建立全国银行位置查询系统(一)——如何创建地图
- ArcGIS API for javascript(4.0)开发笔记 —— 自定义微件位置
- C/C++ Windows API——获取鼠标位置的窗口句柄
- 创建类(点击获得位置信息)—ArcGIS API for JavaScript
- Oracle锁表进程解锁
- 【C/S】——浅谈AppSettings和ConnectionStrings的区别
- [BZOJ 2301] HAOI 2011 Problem b · 莫比乌斯
- Growth发布iOS版 — 距今为止最好的开源“Web开发学习”应用
- Hadoop完全分布式集群安装(Ubuntu)
- 车联网API——位置、距离
- noip2004-合并果子 2008.10.22
- 虚拟机下Linux网络设置几种方式的区别
- BZOJ_P1087&Codevs_P2451 [SCOI2005]互不侵犯King(状态压缩DP)
- 第一行代码-3.6 单位和尺寸
- 挑战极限 Oracle数据库一秒导百万数据
- noip2003加分二叉树 2008.10.30
- Python装饰器学习(九步入门)
- "Edit Document" requires a Microsoft SharePoint Foundation-compatible Application错误的解决方案