程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 微信公眾號開發之LBS,公眾開發lbs

微信公眾號開發之LBS,公眾開發lbs

編輯:關於PHP編程

微信公眾號開發之LBS,公眾開發lbs


百度地圖Web服務api:http://lbsyun.baidu.com/index.php?title=webapi

1.測距

Route Matrix API v2.0:http://lbsyun.baidu.com/index.php?title=webapi/route-matrix-api-v2

1 case "location"://地理位置信息 2 $location_X = $postObj->Location_X; 3 $location_Y = $postObj->Location_Y; 4 $geourl="http://api.map.baidu.com/routematrix/v2/walking?output=xml" 5 ."&origins=30.281341,120.209929&destinations={$location_X},{$location_Y}" 6 ."&ak=f6UkU0QqVAhABUeGKSxZBCeb"; 7 $apistr = file_get_contents($geourl); 8 $apiobj = simplexml_load_string($apistr); 9 $distanceobj = $apiobj->result->distance->value;//距離 10 $durationobj = $apiobj->result->duration->text;//時間 11 $label = $postObj->Label; 12 $contentStr = "你發送的地理位置是:"."\n".$label.",\n"."經度是:".$location_Y.",\n"."緯度是:".$location_X 13 .",\n"."你到我們店鋪還需要步行{$distanceobj}米,大約需要{$durationobj}."; 14 break; 測距

2.導航

UPI API:http://lbsyun.baidu.com/index.php?title=uri/api/web(接口說明-》web端-》公交、駕車、步行導航)

1 case "location"://地理位置信息 2 $location_X = $postObj->Location_X;//緯度 3 $location_Y = $postObj->Location_Y;//經度 4 $geourl="http://api.map.baidu.com/routematrix/v2/walking?output=xml" 5 ."&origins=30.281341,120.209929&destinations={$location_X},{$location_Y}" 6 ."&ak=f6UkU0QqVAhABUeGKSxZBCeb"; 7 $apistr = file_get_contents($geourl); 8 $apiobj = simplexml_load_string($apistr); 9 $distanceobj = $apiobj->result->distance->value;//距離 10 $durationobj = $apiobj->result->duration->text;//時間 11 $label = $postObj->Label; 12 $contentStr = "你發送的地理位置是:"."\n".$label.",\n"."經度是:".$location_Y.",\n"."緯度是:".$location_X 13 .",\n"."你到我們店鋪還需要步行{$distanceobj}米,大約需要{$durationobj}."."\n" 14 ."<a href=\"http://api.map.baidu.com/direction?origin=latlng:{$location_X},{$location_Y}" 15 ."|name:{$label}&destination=latlng:30.281341,120.209929|name:艮山西路233號新東升市場" 16 ."&mode=walking&output=html&region=杭州&src=yourCompanyName|yourAppName\">步行導航</a>"; 17 break; 步行導航

3.全景圖

UPI API:http://lbsyun.baidu.com/index.php?title=uri/api/web(接口說明-》web端-》全景服務)

1 case "location"://地理位置信息 2 $location_X = $postObj->Location_X;//緯度 3 $location_Y = $postObj->Location_Y;//經度 4 $geourl="http://api.map.baidu.com/routematrix/v2/walking?output=xml" 5 ."&origins=30.281341,120.209929&destinations={$location_X},{$location_Y}" 6 ."&ak=f6UkU0QqVAhABUeGKSxZBCeb"; 7 $apistr = file_get_contents($geourl); 8 $apiobj = simplexml_load_string($apistr); 9 $distanceobj = $apiobj->result->distance->value;//距離 10 $durationobj = $apiobj->result->duration->text;//時間 11 $label = $postObj->Label; 12 $contentStr = "你發送的地理位置是:"."\n".$label.",\n"."經度是:".$location_Y.",\n"."緯度是:".$location_X 13 .",\n"."你到我們店鋪還需要步行{$distanceobj}米,大約需要{$durationobj}."."\n" 14 ."<a href=\"http://api.map.baidu.com/direction?origin=latlng:{$location_X},{$location_Y}" 15 ."|name:{$label}&destination=latlng:30.281341,120.209929|name:艮山西路233號新東升市場" 16 ."&mode=walking&output=html&region=杭州&src=yourCompanyName|yourAppName\">查看步行導航</a>"."\n" 17 ."<a href=\"http://api.map.baidu.com/pano/?x={$location_Y}&y={$location_X}&lc=0&ak=f6UkU0QqVAhABUeGKSxZBCeb\">" 18 ."查看你所在位置的全景圖</a>"; 19 break; 全景圖

4.天氣

車聯網API:http://developer.baidu.com/map/wiki/index.php?title=car/api/weather(接口說明-》天氣查詢)

1 case "天氣": 2 $weatherurl="http://api.map.baidu.com/telematics/v3/weather?location=杭州&ak=f6UkU0QqVAhABUeGKSxZBCeb"; 3 $apistr = file_get_contents($weatherurl); 4 $apiobj = simplexml_load_string($apistr); 5 $placeobj = $apiobj->results->currentCity;//讀取城市名 6 $todayobj = $apiobj->results->weather_data->date;//讀取當前時間 7 $weatherobj = $apiobj->results->weather_data->weather;//讀取天氣 8 $windobj = $apiobj->results->weather_data->wind;//讀取風力 9 $temobj = $apiobj->results->weather_data->temperature;//讀取溫度 10 $pm25obj = $apiobj->results->pm25;//讀取pm2.5 11 $contentStr = "{$placeobj}{$todayobj},天氣:{$weatherobj},風力:{$windobj},溫度:{$temobj},pm2.5:{$pm25obj}."; 12 break; 天氣

還可以通過地理位置返回天氣信息。(case "location":略)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved