바이두 지도 웹 서비스 API: http://lbsyun.baidu.com/index.php?title=webapi
1. 배열
경로 매트릭스 API v2.0: http://lbsyun.baidu.com/index.php?title=webapi/route-matrix-api-v2
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">case</span> "location":<span style="color: #008000;">//</span><span style="color: #008000;">地理位置信息</span> <span style="color: #008080;"> 2</span> <span style="color: #800080;">$location_X</span> = <span style="color: #800080;">$postObj</span>-><span style="color: #000000;">Location_X; </span><span style="color: #008080;"> 3</span> <span style="color: #800080;">$location_Y</span> = <span style="color: #800080;">$postObj</span>-><span style="color: #000000;">Location_Y; </span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$geourl</span>="http://api.map.baidu.com/routematrix/v2/walking?output=xml" <span style="color: #008080;"> 5</span> ."&origins=30.281341,120.209929&destinations={<span style="color: #800080;">$location_X</span>},{<span style="color: #800080;">$location_Y</span>}" <span style="color: #008080;"> 6</span> ."&ak=f6UkU0QqVAhABUeGKSxZBCeb"<span style="color: #000000;">; </span><span style="color: #008080;"> 7</span> <span style="color: #800080;">$apistr</span> = <span style="color: #008080;">file_get_contents</span>(<span style="color: #800080;">$geourl</span><span style="color: #000000;">); </span><span style="color: #008080;"> 8</span> <span style="color: #800080;">$apiobj</span> = <span style="color: #008080;">simplexml_load_string</span>(<span style="color: #800080;">$apistr</span><span style="color: #000000;">); </span><span style="color: #008080;"> 9</span> <span style="color: #800080;">$distanceobj</span> = <span style="color: #800080;">$apiobj</span>->result->distance->value;<span style="color: #008000;">//</span><span style="color: #008000;">距离</span> <span style="color: #008080;">10</span> <span style="color: #800080;">$durationobj</span> = <span style="color: #800080;">$apiobj</span>->result->duration->text;<span style="color: #008000;">//</span><span style="color: #008000;">时间</span> <span style="color: #008080;">11</span> <span style="color: #800080;">$label</span> = <span style="color: #800080;">$postObj</span>-><span style="color: #000000;">Label; </span><span style="color: #008080;">12</span> <span style="color: #800080;">$contentStr</span> = "你发送的地理位置是:"."\n".<span style="color: #800080;">$label</span>.",\n"."经度是:".<span style="color: #800080;">$location_Y</span>.",\n"."纬度是:".<span style="color: #800080;">$location_X</span> <span style="color: #008080;">13</span> .",\n"."你到我们店铺还需要步行{<span style="color: #800080;">$distanceobj</span>}米,大约需要{<span style="color: #800080;">$durationobj</span>}."<span style="color: #000000;">; </span><span style="color: #008080;">14</span> <span style="color: #0000ff;">break</span>;
2. 내비게이션
UPI API: http://lbsyun.baidu.com/index.php?title=uri/api/web (인터페이스 설명-》웹측-》버스, 운전, 도보 내비게이션)
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">case</span> "location":<span style="color: #008000;">//</span><span style="color: #008000;">地理位置信息</span> <span style="color: #008080;"> 2</span> <span style="color: #800080;">$location_X</span> = <span style="color: #800080;">$postObj</span>->Location_X;<span style="color: #008000;">//</span><span style="color: #008000;">纬度</span> <span style="color: #008080;"> 3</span> <span style="color: #800080;">$location_Y</span> = <span style="color: #800080;">$postObj</span>->Location_Y;<span style="color: #008000;">//</span><span style="color: #008000;">经度</span> <span style="color: #008080;"> 4</span> <span style="color: #800080;">$geourl</span>="http://api.map.baidu.com/routematrix/v2/walking?output=xml" <span style="color: #008080;"> 5</span> ."&origins=30.281341,120.209929&destinations={<span style="color: #800080;">$location_X</span>},{<span style="color: #800080;">$location_Y</span>}" <span style="color: #008080;"> 6</span> ."&ak=f6UkU0QqVAhABUeGKSxZBCeb"<span style="color: #000000;">; </span><span style="color: #008080;"> 7</span> <span style="color: #800080;">$apistr</span> = <span style="color: #008080;">file_get_contents</span>(<span style="color: #800080;">$geourl</span><span style="color: #000000;">); </span><span style="color: #008080;"> 8</span> <span style="color: #800080;">$apiobj</span> = <span style="color: #008080;">simplexml_load_string</span>(<span style="color: #800080;">$apistr</span><span style="color: #000000;">); </span><span style="color: #008080;"> 9</span> <span style="color: #800080;">$distanceobj</span> = <span style="color: #800080;">$apiobj</span>->result->distance->value;<span style="color: #008000;">//</span><span style="color: #008000;">距离</span> <span style="color: #008080;">10</span> <span style="color: #800080;">$durationobj</span> = <span style="color: #800080;">$apiobj</span>->result->duration->text;<span style="color: #008000;">//</span><span style="color: #008000;">时间</span> <span style="color: #008080;">11</span> <span style="color: #800080;">$label</span> = <span style="color: #800080;">$postObj</span>-><span style="color: #000000;">Label; </span><span style="color: #008080;">12</span> <span style="color: #800080;">$contentStr</span> = "你发送的地理位置是:"."\n".<span style="color: #800080;">$label</span>.",\n"."经度是:".<span style="color: #800080;">$location_Y</span>.",\n"."纬度是:".<span style="color: #800080;">$location_X</span> <span style="color: #008080;">13</span> .",\n"."你到我们店铺还需要步行{<span style="color: #800080;">$distanceobj</span>}米,大约需要{<span style="color: #800080;">$durationobj</span>}."."\n" <span style="color: #008080;">14</span> ."<a href=\"http://api.map.baidu.com/direction?origin=latlng:{<span style="color: #800080;">$location_X</span>},{<span style="color: #800080;">$location_Y</span>}" <span style="color: #008080;">15</span> ."|name:{<span style="color: #800080;">$label</span>}&destination=latlng:30.281341,120.209929|name:艮山西路233号新东升市场" <span style="color: #008080;">16</span> ."&mode=walking&output=html®ion=杭州&src=yourCompanyName|yourAppName\">步行导航</a>"<span style="color: #000000;">; </span><span style="color: #008080;">17</span> <span style="color: #0000ff;">break</span>;
3. 파노라마
UPI API: http://lbsyun.baidu.com/index.php?title=uri/api/web (인터페이스 설명-》웹사이드-》파노라마 서비스)
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">case</span> "location":<span style="color: #008000;">//</span><span style="color: #008000;">地理位置信息</span> <span style="color: #008080;"> 2</span> <span style="color: #800080;">$location_X</span> = <span style="color: #800080;">$postObj</span>->Location_X;<span style="color: #008000;">//</span><span style="color: #008000;">纬度</span> <span style="color: #008080;"> 3</span> <span style="color: #800080;">$location_Y</span> = <span style="color: #800080;">$postObj</span>->Location_Y;<span style="color: #008000;">//</span><span style="color: #008000;">经度</span> <span style="color: #008080;"> 4</span> <span style="color: #800080;">$geourl</span>="http://api.map.baidu.com/routematrix/v2/walking?output=xml" <span style="color: #008080;"> 5</span> ."&origins=30.281341,120.209929&destinations={<span style="color: #800080;">$location_X</span>},{<span style="color: #800080;">$location_Y</span>}" <span style="color: #008080;"> 6</span> ."&ak=f6UkU0QqVAhABUeGKSxZBCeb"<span style="color: #000000;">; </span><span style="color: #008080;"> 7</span> <span style="color: #800080;">$apistr</span> = <span style="color: #008080;">file_get_contents</span>(<span style="color: #800080;">$geourl</span><span style="color: #000000;">); </span><span style="color: #008080;"> 8</span> <span style="color: #800080;">$apiobj</span> = <span style="color: #008080;">simplexml_load_string</span>(<span style="color: #800080;">$apistr</span><span style="color: #000000;">); </span><span style="color: #008080;"> 9</span> <span style="color: #800080;">$distanceobj</span> = <span style="color: #800080;">$apiobj</span>->result->distance->value;<span style="color: #008000;">//</span><span style="color: #008000;">距离</span> <span style="color: #008080;">10</span> <span style="color: #800080;">$durationobj</span> = <span style="color: #800080;">$apiobj</span>->result->duration->text;<span style="color: #008000;">//</span><span style="color: #008000;">时间</span> <span style="color: #008080;">11</span> <span style="color: #800080;">$label</span> = <span style="color: #800080;">$postObj</span>-><span style="color: #000000;">Label; </span><span style="color: #008080;">12</span> <span style="color: #800080;">$contentStr</span> = "你发送的地理位置是:"."\n".<span style="color: #800080;">$label</span>.",\n"."经度是:".<span style="color: #800080;">$location_Y</span>.",\n"."纬度是:".<span style="color: #800080;">$location_X</span> <span style="color: #008080;">13</span> .",\n"."你到我们店铺还需要步行{<span style="color: #800080;">$distanceobj</span>}米,大约需要{<span style="color: #800080;">$durationobj</span>}."."\n" <span style="color: #008080;">14</span> ."<a href=\"http://api.map.baidu.com/direction?origin=latlng:{<span style="color: #800080;">$location_X</span>},{<span style="color: #800080;">$location_Y</span>}" <span style="color: #008080;">15</span> ."|name:{<span style="color: #800080;">$label</span>}&destination=latlng:30.281341,120.209929|name:艮山西路233号新东升市场" <span style="color: #008080;">16</span> ."&mode=walking&output=html®ion=杭州&src=yourCompanyName|yourAppName\">查看步行导航</a>"."\n" <span style="color: #008080;">17</span> ."<a href=\"http://api.map.baidu.com/pano/?x={<span style="color: #800080;">$location_Y</span>}&y={<span style="color: #800080;">$location_X</span>}&lc=0&ak=f6UkU0QqVAhABUeGKSxZBCeb\">" <span style="color: #008080;">18</span> ."查看你所在位置的全景图</a>"<span style="color: #000000;">; </span><span style="color: #008080;">19</span> <span style="color: #0000ff;">break</span>;
4. 날씨
자동차 인터넷 API: http://developer.baidu.com/map/wiki/index.php?title=car/api/weather(인터페이스 설명-"날씨 쿼리)
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">case</span> "天气": <span style="color: #008080;"> 2</span> <span style="color: #800080;">$weatherurl</span>="http://api.map.baidu.com/telematics/v3/weather?location=杭州&ak=f6UkU0QqVAhABUeGKSxZBCeb"<span style="color: #000000;">; </span><span style="color: #008080;"> 3</span> <span style="color: #800080;">$apistr</span> = <span style="color: #008080;">file_get_contents</span>(<span style="color: #800080;">$weatherurl</span><span style="color: #000000;">); </span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$apiobj</span> = <span style="color: #008080;">simplexml_load_string</span>(<span style="color: #800080;">$apistr</span><span style="color: #000000;">); </span><span style="color: #008080;"> 5</span> <span style="color: #800080;">$placeobj</span> = <span style="color: #800080;">$apiobj</span>->results->currentCity;<span style="color: #008000;">//</span><span style="color: #008000;">读取城市名</span> <span style="color: #008080;"> 6</span> <span style="color: #800080;">$todayobj</span> = <span style="color: #800080;">$apiobj</span>->results->weather_data-><span style="color: #008080;">date</span>;<span style="color: #008000;">//</span><span style="color: #008000;">读取当前时间</span> <span style="color: #008080;"> 7</span> <span style="color: #800080;">$weatherobj</span> = <span style="color: #800080;">$apiobj</span>->results->weather_data->weather;<span style="color: #008000;">//</span><span style="color: #008000;">读取天气</span> <span style="color: #008080;"> 8</span> <span style="color: #800080;">$windobj</span> = <span style="color: #800080;">$apiobj</span>->results->weather_data->wind;<span style="color: #008000;">//</span><span style="color: #008000;">读取风力</span> <span style="color: #008080;"> 9</span> <span style="color: #800080;">$temobj</span> = <span style="color: #800080;">$apiobj</span>->results->weather_data->temperature;<span style="color: #008000;">//</span><span style="color: #008000;">读取温度</span> <span style="color: #008080;">10</span> <span style="color: #800080;">$pm25obj</span> = <span style="color: #800080;">$apiobj</span>->results->pm25;<span style="color: #008000;">//</span><span style="color: #008000;">读取pm2.5</span> <span style="color: #008080;">11</span> <span style="color: #800080;">$contentStr</span> = "{<span style="color: #800080;">$placeobj</span>}{<span style="color: #800080;">$todayobj</span>},天气:{<span style="color: #800080;">$weatherobj</span>},风力:{<span style="color: #800080;">$windobj</span>},温度:{<span style="color: #800080;">$temobj</span>},pm2.5:{<span style="color: #800080;">$pm25obj</span>}."<span style="color: #000000;">; </span><span style="color: #008080;">12</span> <span style="color: #0000ff;">break</span>;
날씨 정보는 지리적 위치에 따라 반환될 수도 있습니다. (대소문자 "위치" : 생략)