标签:
百度地图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®ion=杭州&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®ion=杭州&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":略)
标签:
原文地址:http://www.cnblogs.com/landiljy/p/5750260.html