Bus/station

跳转到: 导航, 搜索
(XML示例)
 
(未显示2个用户的9个中间版本)
第1行: 第1行:
== '''公交线路搜索''' ==
+
== '''bus/station ''' ==
根据线路关键字或城市代码等进行搜索,返回公交线路信息
+
根据线路关键字或城市代码等进行搜索,返回公交站点信息
  
 
== '''URL''' ==
 
== '''URL''' ==
http://api.map.sina.com.cn/bus/line.(json|xml)
+
http://api.t.sina.com.cn/location/bus/station.(json|xml)
  
 
== '''支持格式''' ==
 
== '''支持格式''' ==
第12行: 第12行:
  
 
== '''是否需要登录''' ==
 
== '''是否需要登录''' ==
'''false'''  
+
'''true'''  
 
== '''请求数限制''' ==
 
== '''请求数限制''' ==
 
'''true'''  
 
'''true'''  
第40行: 第40行:
 
| 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)
 
|}
 
|}
  
第53行: 第53行:
 
<pre>
 
<pre>
 
<?xml version="1.0" encoding="UTF-8" ?>  
 
<?xml version="1.0" encoding="UTF-8" ?>  
<geoSearchResult>
+
<geoResult>
 
  <count>10</count>  
 
  <count>10</count>  
 
  <total>114</total>  
 
  <total>114</total>  
  <status>1</status>  
+
  <page>1</page>  
 
  <stations>
 
  <stations>
 
   <station>
 
   <station>
 +
  <name>西直门</name>
 
   <station_info>地铁4号线(公益西桥--安河桥北)</station_info>  
 
   <station_info>地铁4号线(公益西桥--安河桥北)</station_info>  
 +
  <longitude>116.355491</longitude>
 +
  <latitude>39.940484</latitude>
 
   <telephone />  
 
   <telephone />  
 
   <district>110102</district>  
 
   <district>110102</district>  
  <name>西直门</name>
 
  <address />
 
  <longitude>116.355491</longitude>
 
  <latitude>39.940484</latitude>
 
 
   </station>
 
   </station>
 
   ...
 
   ...
 
   </stations>
 
   </stations>
</geoSearchResult>
+
</geoResult>
 +
 
 
</pre>
 
</pre>
  
第77行: 第77行:
 
  "count":"10",
 
  "count":"10",
 
  "total":"114",
 
  "total":"114",
  "status":"1",
+
  "page":"1",
 
  "stations":
 
  "stations":
 
  [
 
  [
 
   {
 
   {
  "station_info":"182.345469,110100024313,\u5730\u94c14\u53f7\u7ebf,\u5730\u94c14\u53f7\u7ebf(\u516c\u76ca\u897f\u6865--\u5b89\u6cb3\u6865\u5317)",
 
  "telephone":"",
 
  "district":"110102",
 
 
   "name":"\u897f\u76f4\u95e8",
 
   "name":"\u897f\u76f4\u95e8",
  "address":"",
+
"station_info":"\u5730\u94c14\u53f7\u7ebf(\u516c\u76ca\u897f\u6865--\u5b89\u6cb3\u6865\u5317)",
 
   "longitude":"116.355491",
 
   "longitude":"116.355491",
 
   "latitude":"39.940484"
 
   "latitude":"39.940484"
 +
"telephone":"",
 +
  "district":"110102",
 
   },
 
   },
 
   ...
 
   ...
 
  ]
 
  ]
 
}
 
}
 +
 
</pre>
 
</pre>
  
第97行: 第97行:
 
:count:返回的结果数
 
:count:返回的结果数
 
:total:结果总数
 
:total:结果总数
:status:标识结果;如该值为0,则没有找到相关的路线信息
+
:page:返回的结果在总结果集中的页码
 
:stations:返回的结果集
 
:stations:返回的结果集
::station_info:途径站点信息(格式:站名,站点node,站点编号,线路关键字,线路名称)
 
::telephone:电话
 
::district:区域代码
 
 
::name:站点名称
 
::name:站点名称
::address:地址
+
::station_info:经过的线路名称
 
::longitude:经度
 
::longitude:经度
 
::latitude:纬度
 
::latitude:纬度
 +
::telephone:电话
 +
::district:区域代码
  
== '''使用示例''' ==
+
== '''其它''' ==
 +
 
 +
===  '''PHP示例''' ===
 +
需要开启PHP的cURL扩展
 
<pre>
 
<pre>
xml:
+
<?php
http://api.map.sina.com.cn/bus/station.xml?q=西直门&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.map.sina.com.cn/bus/station.json?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;
 +
}
 +
?>
 
</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