Bus/station

跳转到: 导航, 搜索
(创建新页面为 '== '''公交线路搜索''' == 根据线路关键字或城市代码等进行搜索,返回公交线路信息 == '''URL''' == http://api.t.sina.com.cn/bus/line.(json|xml) == '…')
 
 
(未显示2个用户的18个中间版本)
第1行: 第1行:
== '''公交线路搜索''' ==
+
== '''bus/station ''' ==
根据线路关键字或城市代码等进行搜索,返回公交线路信息
+
根据线路关键字或城市代码等进行搜索,返回公交站点信息
  
 
== '''URL''' ==
 
== '''URL''' ==
http://api.t.sina.com.cn/bus/line.(json|xml)
+
http://api.t.sina.com.cn/location/bus/station.(json|xml)
  
 
== '''支持格式''' ==
 
== '''支持格式''' ==
第12行: 第12行:
  
 
== '''是否需要登录''' ==
 
== '''是否需要登录''' ==
'''false'''  
+
'''true'''  
 
== '''请求数限制''' ==
 
== '''请求数限制''' ==
 
'''true'''  
 
'''true'''  
 
== '''请求参数''' ==
 
== '''请求参数''' ==
 
{| style="width:100%; height:200px;" border="1" cellspacing="0" cellpadding="0"
 
{| style="width:100%; height:200px;" border="1" cellspacing="0" cellpadding="0"
! style="width:20%;" |参数  
+
! style="text-align:center;width:20%;" |参数  
! style="width:10%" |必选
+
! style="text-align:center;width:10%" |必选
! style="width:20%" |类型及范围
+
! style="text-align:center;width:20%" |类型及范围
! style="width:50%" |说明
+
! style="text-align:center;width:50%" |说明
 
|- style="height:px"  
 
|- style="height:px"  
 
| style="text-align:center;" |source
 
| style="text-align:center;" |source
第35行: 第35行:
 
| style="text-align:center;" |false
 
| style="text-align:center;" |false
 
| style="text-align:center;" |string
 
| style="text-align:center;" |string
| 所在城市代码,默认为0010(北京)
+
| 所在城市代码,默认为0010,(详见[[Location/citycode|城市代码对照表]])
 
|-
 
|-
 
| style="text-align:center;" |page
 
| style="text-align:center;" |page
 
| style="text-align:center;" |false
 
| style="text-align:center;" |false
 
| style="text-align:center;" |int
 
| style="text-align:center;" |int
| 返回结果的页码(默认为1)
+
| 返回结果的页码(默认为1,最大为40)
 
|-
 
|-
 
| style="text-align:center;" |count
 
| style="text-align:center;" |count
 
| style="text-align:center;" |false
 
| style="text-align:center;" |false
 
| style="text-align:center;" |int
 
| style="text-align:center;" |int
| 单页返回的结果条数(默认为10,最大为40)
+
| 单页返回的结果条数(默认为10,最大为50)
 
|}
 
|}
  
第52行: 第52行:
 
===  '''XML示例''' ===
 
===  '''XML示例''' ===
 
<pre>
 
<pre>
<?xml version="1.0" encoding="utf-8" ?>  
+
<?xml version="1.0" encoding="UTF-8" ?>  
<xml>
+
<geoResult>
  <count>1</count>  
+
  <count>10</count>  
  <status>1</status>  
+
  <total>114</total>  
  <list>
+
  <page>1</page>  
<item>
+
<stations>
  <result_id>1</result_id>  
+
   <station>
  <city>0010</city>  
+
   <name>西直门</name>  
   <station_info>;保福寺桥西,116.331676 39.98622,bao fu si qiao xi,310100,1;
+
   <station_info>地铁4号线(公益西桥--安河桥北)</station_info>  
   中关村一街,116.323349 39.9859,zhong guan cun yijie,310100,2;......</station_info>  
+
  <longitude>116.355491</longitude>  
  <q>320路区间</q>  
+
  <latitude>39.940484</latitude>
  <rid>136</rid>    
+
  <telephone />  
  <coordinates>116.331676;39.986227;116.327258;39.986015;......</coordinates>
+
  <district>110102</district>  
  <name>320路区间(保福寺桥西--北京西站北广场)</name>  
+
  </station>
  <front_name>保福寺桥西</front_name>  
+
  ...
  <front_spell>bao fu si qiao xi</front_spell>  
+
   </stations>
  <terminal_name>北京西站北广场</terminal_name>  
+
</geoResult>
  <terminal_spell>bei jing xi zhan bei guang chang</terminal_spell>  
+
 
  <start_time>05:30</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>
+
</item>
+
</list>
+
</xml>
+
 
</pre>
 
</pre>
  
第95行: 第75行:
 
<pre>
 
<pre>
 
{
 
{
  "count":"1",
+
  "count":"10",
  "status":"1",
+
  "total":"114",
  "list":[{
+
  "page":"1",
        "result_id":"1",
+
"stations":
        "city":"0010",
+
[
        "station_info":";\u4fdd\u798f\u5bfa\u6865\u897f,116.331676 39.98622,bao fu si qiao xi,310100,1;
+
  {
        \u4e2d\u5173\u6751\u4e00  \u8857,116.323349 39.9859,zhong guan cun yi jie,310100,2;",
+
  "name":"\u897f\u76f4\u95e8",
        "q":"320\u8def\u533a\u95f4",
+
"station_info":"\u5730\u94c14\u53f7\u7ebf(\u516c\u76ca\u897f\u6865--\u5b89\u6cb3\u6865\u5317)",
        "rid":"136",
+
  "longitude":"116.355491",
        "coordinates":"116.331676;39.986227;......",
+
  "latitude":"39.940484"
        "name":"320\u8def\u533a\u95f4(\u4fdd\u798f\u5bfa\u6865\u897f--\u5317\u4eac\u897f\u7ad9\u5317\u5e7f\u573a)",
+
"telephone":"",
        "front_name":"\u4fdd\u798f\u5bfa\u6865\u897f",
+
  "district":"110102",
        "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:30",
+
        "end_time":"23:00",
+
        "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"}]
+
 
}
 
}
 +
 
</pre>
 
</pre>
  
 
===  '''字段说明 ''' ===
 
===  '''字段说明 ''' ===
 
:count:返回的结果数
 
:count:返回的结果数
:status:标识结果;如该值为0,则没有找到相关的路线信息
+
:total:结果总数
:list:返回的结果集
+
:page:返回的结果在总结果集中的页码
::result_id:结果id
+
:stations:返回的结果集
::rid:线路数据id
+
::name:站点名称
::name:线路名称
+
::station_info:经过的线路名称
::city:城市代码
+
::longitude:经度
::q:线路关键字
+
::latitude:纬度
::front_name:起点名称
+
::telephone:电话
::front_spell:起点拼音
+
::district:区域代码
::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:类型
+
::station_info:途径站点信息(格式:‘;’分隔,站名,经度 纬度,拼音,区域id,站点在本线路的序号)
+
::coordinates:线路坐标串(格式:’;’分隔,经度;纬度;经度;纬度;)
+
  
== '''使用示例''' ==
+
== '''其它''' ==
 +
 
 +
===  '''PHP示例''' ===
 +
需要开启PHP的cURL扩展
 
<pre>
 
<pre>
xml:
+
<?php
http://api.t.sina.com.cn/bus/line.xml?q=320&source=appkey
+
//改为你的微博账号,用户名和密码之间用:隔开
 +
$userPwd = 'user@sina.com:pwd';
 +
//改为你微博应用的appkey
 +
$appkey = '0123456789';
 +
//查询关键词
 +
$q = urlencode("海淀南路");
  
json:
+
$url = "http://api.t.sina.com.cn/location/bus/station.xml?city=0010&q=$q&source=$appkey";
http://api.t.sina.com.cn/bus/line.json?q=320&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;
 +
}
 +
?>
 
</pre>
 
</pre>

2012年9月24日 (一) 11:51的最后版本

目录

bus/station

根据线路关键字或城市代码等进行搜索,返回公交站点信息

URL

http://api.t.sina.com.cn/location/bus/station.(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>10</count> 
 <total>114</total> 
 <page>1</page> 
 <stations>
  <station>
   <name>西直门</name> 
   <station_info>地铁4号线(公益西桥--安河桥北)</station_info> 
   <longitude>116.355491</longitude> 
   <latitude>39.940484</latitude>
   <telephone /> 
   <district>110102</district> 
   </station>
   ...
  </stations>
</geoResult>

JSON示例

{
 "count":"10",
 "total":"114",
 "page":"1",
 "stations":
 [
  {
   "name":"\u897f\u76f4\u95e8",
"station_info":"\u5730\u94c14\u53f7\u7ebf(\u516c\u76ca\u897f\u6865--\u5b89\u6cb3\u6865\u5317)",
   "longitude":"116.355491",
   "latitude":"39.940484"
"telephone":"",
   "district":"110102",
  },
  ...
 ]
}

字段说明

count:返回的结果数
total:结果总数
page:返回的结果在总结果集中的页码
stations:返回的结果集
name:站点名称
station_info:经过的线路名称
longitude:经度
latitude:纬度
telephone:电话
district:区域代码

其它

PHP示例

需要开启PHP的cURL扩展

<?php
//改为你的微博账号,用户名和密码之间用:隔开
$userPwd = 'user@sina.com:pwd';
//改为你微博应用的appkey
$appkey = '0123456789';
//查询关键词
$q = urlencode("海淀南路");

$url = "http://api.t.sina.com.cn/location/bus/station.xml?city=0010&q=$q&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;
}
?>
文档更新时间: 2012-09-24