Bus/line
Zhangchao2 (讨论 | 贡献) (→使用示例) |
|||
第192行: | 第192行: | ||
:::telephone:电话 | :::telephone:电话 | ||
:::address:地址 | :::address:地址 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== '''其它''' == | == '''其它''' == | ||
第240行: | 第232行: | ||
} | } | ||
?> | ?> | ||
− | </pre> | + | </pre>{{#a:showgrade}} |
2011年8月11日 (四) 14:24的版本
目录 |
bus/line
根据线路关键字或城市代码等进行搜索,返回公交线路信息
URL
http://api.t.sina.com.cn/location/bus/line.(json%7Cxml)
支持格式
XML/JSON
HTTP请求方式
GET
是否需要登录
true
请求数限制
true
请求参数
参数 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份 |
q | true | string | 搜索关键字 |
city | false | string | 所在城市代码,默认为0010,(详见城市代码对照表) |
page | false | int | 返回结果的页码(默认为1,最大为40) |
count | false | int | 单页返回的结果条数(默认为10,最大为50) |
返回结果
XML示例
<?xml version="1.0" encoding="UTF-8" ?> <geoResult> <count>4</count> <page>1</page> <lines> <line> <q>320路区间</q> <city>0010</city> <name>320路区间(保福寺桥西--北京西站北广场)</name> <front_name>保福寺桥西</front_name> <front_spell>bao fu si qiao xi</front_spell> <terminal_name>北京西站北广场</terminal_name> <terminal_spell>bei jing xi zhan bei guang chang</terminal_spell> <start_time>05:00</start_time> <end_time>23:00</end_time> <service_period /> <time_desc /> <company>北京公交集团第六客运分公司</company> <length>13.2563</length> <basic_price>1</basic_price> <total_price>1</total_price> <air>0</air> <commutation_ticket>0</commutation_ticket> <status>1</status> <auto>1</auto> <ic_card>1</ic_card> <express_way>0</express_way> <double_deck>0</double_deck> <description>北京公交集团第六客运分公司</description> <type>1</type> <coordinates>116.331676;39.986227;......</coordinates> <stations> <station> <name>保福寺桥西</name> <longitude>116.331676</longitude> <latitude>39.98622</latitude> <district>310100</district> <station_info /> <telephone /> <address /> </station> ... </stations> </line> ... </lines> </geoResult>
JSON示例
{ "count":"4", "page":"1", "lines": [ { "q":"320\u8def\u533a\u95f4", "city":"0010", "name":"320\u8def\u533a\u95f4(\u4fdd\u798f\u5bfa\u6865\u897f--\u5317\u4eac\u897f\u7ad9\u5317\u5e7f\u573a)", "front_name":"\u4fdd\u798f\u5bfa\u6865\u897f", "front_spell":"bao fu si qiao xi", "terminal_name":"\u5317\u4eac\u897f\u7ad9\u5317\u5e7f\u573a", "terminal_spell":"bei jing xi zhan bei guang chang", "start_time":"05:", "end_time":"23:", "service_period":"", "time_desc":"", "company":"\u5317\u4eac\u516c\u4ea4\u96c6\u56e2\u7b2c\u516d\u5ba2\u8fd0\u5206\u516c\u53f8", "length":"13.2563", "basic_price":"1", "total_price":"1", "air":"0", "commutation_ticket":"0", "status":"1", "auto":"1", "ic_card":"1", "express_way":"0", "double_deck":"0", "description":"\u5317\u4eac\u516c\u4ea4\u96c6\u56e2\u7b2c\u516d\u5ba2\u8fd0\u5206\u516c\u53f8", "type":"1", "coordinates":"116.331676;39.986227;...", "stations": [ { "name":"\u4fdd\u798f\u5bfa\u6865\u897f", "longitude":"116.331676", "latitude":"39.98622", "district":"310100", "station_info":"", "telephone":"", "address":"" }, ... ] }, ... ] }
字段说明
- count:当前返回的结果数
- page:当前返回的结果在总结果集中的页数
- lines:当前返回的结果集
- q:线路关键字
- city:城市代码
- name:线路名称
- front_name:起点名称
- front_spell:起点拼音
- terminal_name:终点名称
- terminal_name:终点拼音
- start_time:首班车时间
- end_time:末班时间
- service_period:区间
- time_desc:时间说明
- company:运营公司
- length:总长度
- basic_price:起步价
- total_price:全程票价
- air:是否有空调
- commutation_ticket:是否能使用月票
- status:状态
- auto:无人售票
- ic_card:是否能刷IC卡
- express_way:是否快车
- double_deck:是否双层车
- description:线路描述
- type:类型
- coordinates:线路坐标串(格式:’;’分隔,经度;纬度;经度;纬度;)
- stations:途径站点集
- name:站名
- longitude:站点经度
- latitude:站点纬度
- district:区
- station_info:站点详情
- telephone:电话
- address:地址
其它
PHP示例
需要开启PHP的cURL扩展
<?php //改为你的微博账号,用户名和密码之间用:隔开 $userPwd = 'user@sina.com:pwd'; //改为你微博应用的appkey $appkey = '0123456789'; //查询关键词 $q = urlencode("320"); $url = "http://api.t.sina.com.cn/location/bus/line.xml?q=$q&city=0010&source=$appkey"; $rst = curlSample($url,$userPwd); echo $rst; function curlSample($url,$userPwd,$postFields = '',$header = ''){ $ch = curl_init() or die (curl_error()) ; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_TIMEOUT,30); if(!empty($userPwd)){ curl_setopt($ch,CURLOPT_USERPWD,$userPwd); } if(!empty($postFields)){ curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$postFields); } if(!empty($header)){ curl_setopt($ch, CURLOPT_HTTPHEADER,$header); } $result = curl_exec($ch) or die (curl_error($ch)); curl_close($ch); return $result; } ?>