Home  >  Article  >  php教程  >  WeChat public account development LBS

WeChat public account development LBS

WBOY
WBOYOriginal
2016-08-10 08:49:352136browse

Baidu map web service api: http://lbsyun.baidu.com/index.php?title=webapi

1.Ranging

Route Matrix 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>;
Ranging

2.Navigation

UPI API: http://lbsyun.baidu.com/index.php?title=uri/api/web (Interface description-》web side-》Bus, driving, walking navigation)

<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&region=杭州&src=yourCompanyName|yourAppName\">步行导航</a>"<span style="color: #000000;">;
</span><span style="color: #008080;">17</span>                     <span style="color: #0000ff;">break</span>;
Walking Navigation

3. Panorama

UPI API: http://lbsyun.baidu.com/index.php?title=uri/api/web (Interface Description-》Web Side-》Panoramic Service)

<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&region=杭州&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>;
Panorama

4.Weather

Car Internet API: http://developer.baidu.com/map/wiki/index.php?title=car/api/weather (Interface Description-》Weather Query)

<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>;
Weather

You can also return weather information through geographical location. (case "location": omitted)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn