Geocode/address to geo
Zhangchao2 (讨论 | 贡献) (→字段说明) |
|||
(未显示1个用户的8个中间版本) | |||
第1行: | 第1行: | ||
− | == ''' | + | == '''geocode/address_to_geo''' == |
根据地址返回坐标的接口 | 根据地址返回坐标的接口 | ||
== '''URL''' == | == '''URL''' == | ||
− | http://api.t.sina.com.cn/geocode/address_to_geo.(json|xml) | + | http://api.t.sina.com.cn/location/geocode/address_to_geo.(json|xml) |
== '''支持格式''' == | == '''支持格式''' == | ||
第12行: | 第12行: | ||
== '''是否需要登录''' == | == '''是否需要登录''' == | ||
− | ''' | + | '''true''' |
== '''请求数限制''' == | == '''请求数限制''' == | ||
'''true''' | '''true''' | ||
第30行: | 第30行: | ||
| style="text-align:center;" |true | | style="text-align:center;" |true | ||
| style="text-align:center;" |string | | style="text-align:center;" |string | ||
− | | 需要获取坐标的地址 | + | | 需要获取坐标的地址 |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|} | |} | ||
第43行: | 第38行: | ||
<pre> | <pre> | ||
<?xml version="1.0" encoding="UTF-8" ?> | <?xml version="1.0" encoding="UTF-8" ?> | ||
− | < | + | <geoResult> |
<status>1</status> | <status>1</status> | ||
<geo> | <geo> | ||
第51行: | 第46行: | ||
<latitude>39.984213</latitude> | <latitude>39.984213</latitude> | ||
</geo> | </geo> | ||
− | </ | + | </geoResult> |
− | + | ||
=== '''JSON示例''' === | === '''JSON示例''' === | ||
第71行: | 第65行: | ||
:status:状态 | :status:状态 | ||
:geo:geo信息 | :geo:geo信息 | ||
− | :: | + | ::exactitude:置信度(可能为空) |
− | + | ::name:匹配到的地址名称 | |
− | + | ::longitude:匹配到的坐标经度 | |
− | + | ::latitude:匹配到的坐标纬度 | |
− | == ''' | + | == '''其它''' == |
+ | |||
+ | === '''PHP示例''' === | ||
+ | 需要开启PHP的cURL扩展 | ||
<pre> | <pre> | ||
− | + | <?php | |
− | + | //改为你的微博账号,用户名和密码之间用:隔开 | |
+ | $userPwd = 'user@sina.com:pwd'; | ||
+ | //改为你微博应用的appkey | ||
+ | $appkey = '0123456789'; | ||
+ | //查询关键词 | ||
+ | $q = urlencode("海淀"); | ||
− | + | $url = "http://api.t.sina.com.cn/location/geocode/address_to_geo.xml?address=$q&source=$appkey"; | |
− | http://api.t.sina.com.cn/geocode/address_to_geo. | + | |
+ | $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> |
2011年8月11日 (四) 14:26的最后版本
目录 |
geocode/address_to_geo
根据地址返回坐标的接口
URL
http://api.t.sina.com.cn/location/geocode/address_to_geo.(json%7Cxml)
支持格式
XML/JSON
HTTP请求方式
GET
是否需要登录
true
请求数限制
true
请求参数
参数 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份 |
address | true | string | 需要获取坐标的地址 |
返回结果
XML示例
<?xml version="1.0" encoding="UTF-8" ?> <geoResult> <status>1</status> <geo> <exactitude>1.000000</exactitude> <name>中国北京市海淀区中关村</name> <longitude>116.324416</longitude> <latitude>39.984213</latitude> </geo> </geoResult> === '''JSON示例''' === <pre> { "status":1, "geo": { "exactitude":"1.000000", "name":"\u4e2d\u56fd\u5317\u4eac\u5e02\u6d77\u6dc0\u533a\u4e2d\u5173\u6751", "longitude":"116.324416", "latitude":"39.984213" } }
字段说明
- status:状态
- geo:geo信息
- exactitude:置信度(可能为空)
- name:匹配到的地址名称
- longitude:匹配到的坐标经度
- latitude:匹配到的坐标纬度
其它
PHP示例
需要开启PHP的cURL扩展
<?php //改为你的微博账号,用户名和密码之间用:隔开 $userPwd = 'user@sina.com:pwd'; //改为你微博应用的appkey $appkey = '0123456789'; //查询关键词 $q = urlencode("海淀"); $url = "http://api.t.sina.com.cn/location/geocode/address_to_geo.xml?address=$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; } ?>
文档更新时间: 2011-08-11