Pois/keyword
Zhangchao2 (讨论 | 贡献) (→使用示例) |
|||
(未显示2个用户的3个中间版本) | |||
第126行: | 第126行: | ||
::province:省份 | ::province:省份 | ||
− | == ''' | + | == '''其它''' == |
− | + | ||
− | + | === '''PHP示例''' === | |
− | + | 需要开启PHP的cURL扩展 | |
+ | <pre> | ||
+ | <?php | ||
+ | //改为你的微博账号,用户名和密码之间用:隔开 | ||
+ | $userPwd = 'user@sina.com:pwd'; | ||
+ | //改为你微博应用的appkey | ||
+ | $appkey = '0123456789'; | ||
+ | //查询关键词 | ||
+ | $q = urlencode("123"); | ||
− | + | $url = "http://api.t.sina.com.cn/location/pois/keyword.xml?source=$appkey&q=$q"; | |
− | + | ||
+ | $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> |
2012年9月24日 (一) 11:49的最后版本
目录 |
pois/keyword
根据关键字和(或)分类进行搜索,返回相关的poi点信息。
URL
http://api.t.sina.com.cn/location/pois/keyword.(json%7Cxml)
支持格式
XML/JSON
HTTP请求方式
GET
是否需要登录
true
请求数限制
true
请求参数
参数 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。 |
q | false | string | 查询的关键字,q和category至少填一项 |
category | false | string | 查询poi分类代码(详见分类代码对应表) |
city | false | string | 城市代码(不填城市代码,默认在全国搜索,详见城市代码对照表) |
注意:一次调用最多只返回50条记录,若有其他需求请及时与我们取得联系 | |||
page | false | int | 返回的首条结果在结果集中的页码(默认为1,最大为40) |
count | false | int | 返回的结果集中每页的结果数(默认为10,最大为50) |
返回结果
XML示例
<?xml version="1.0" encoding="utf-8" ?> <geoResult> <total>695</total> <count>2</count> <page>1</page> <pois> <poi> <spid>P010A00CHR9</pid> <name>123烤鸡翅</name> <address>石景山区石景山路22号长城大厦附近</address> <category>50000</category> <navigator>餐饮相关</navigator> <telephone /> <pic_url /> <longitude>116.22074</longitude> <latitude>39.90652</latitude> <city>北京</city> <province>北京</city> </poi> ... </pois> </geoResult>
JSON示例
{ "total":"695", "count":"2", "page":"1", "pois": [{ "spid":"P010A00CHR9", "name":"123\u70e4\u9e21\u7fc5", "address":"\u77f3\u666f\u5c71\u533a\u77f3\u666f\u5c71\u8def22\u53f7\u957f\u57ce\u5927\u53a6\u9644\u8fd1", "category":"50000", "navigator":"\u9910\u996e\u76f8\u5173", "telephone":"", "pic_url":"", "longitude":"116.22074", "latitude":"39.90652", "city":"北京", "province":"北京" }, ... ] }
字段说明
- total:结果总数
- count:本页返回的结果数
- page:返回的首条结果在结果集中的页码
- pois:结果poi集
- spid:本条poi记录的spid
- name:poi点名称
- address:poi点的地址
- category:poi点的分类(详见分类代码表)
- navigator:poi点的分类名称
- telephone:poi点的电话
- pic_url:poi点的图片地址
- longitude:poi点的经度
- latitude:poi点的纬度
- city:城市
- province:省份
其它
PHP示例
需要开启PHP的cURL扩展
<?php //改为你的微博账号,用户名和密码之间用:隔开 $userPwd = 'user@sina.com:pwd'; //改为你微博应用的appkey $appkey = '0123456789'; //查询关键词 $q = urlencode("123"); $url = "http://api.t.sina.com.cn/location/pois/keyword.xml?source=$appkey&q=$q"; $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