Base/get map image
Zhangchao2 (讨论 | 贡献) (→静态地图) |
|||
(未显示1个用户的3个中间版本) | |||
第3行: | 第3行: | ||
== '''URL''' == | == '''URL''' == | ||
− | http://api.t.sina.com.cn/base/get_map_image.(xml|json) | + | http://api.t.sina.com.cn/location/base/get_map_image.(xml|json) |
== '''支持格式''' == | == '''支持格式''' == | ||
第136行: | 第136行: | ||
{"url":"http:\/\/202.108.5.66:8081\/MapServerBM\/maptemp\/20114\/817\/1302254393724_37.png"} | {"url":"http:\/\/202.108.5.66:8081\/MapServerBM\/maptemp\/20114\/817\/1302254393724_37.png"} | ||
</pre> | </pre> | ||
− | == ''' | + | |
+ | == '''其它''' == | ||
+ | |||
+ | === '''PHP示例''' === | ||
+ | 需要开启PHP的cURL扩展 | ||
<pre> | <pre> | ||
− | + | <?php | |
+ | //改为你的微博账号,用户名和密码之间用:隔开 | ||
+ | $userPwd = 'user@sina.com:pwd'; | ||
+ | //改为你微博应用的appkey | ||
+ | $appkey = '0123456789'; | ||
+ | |||
+ | $url = "http://api.t.sina.com.cn/location/base/get_map_image.xml?center_coordinates=116.3136,39.9824&zoom=12&img_format=png&coordinates=116.3136,39.98&names=hello&size=400x400&icons=105&px=1&traffic=on&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> |
2011年8月11日 (四) 14:21的最后版本
目录 |
base/get_map_image
根据中心点生成静态地图的图片
URL
http://api.t.sina.com.cn/location/base/get_map_image.(xml%7Cjson)
支持格式
xml/json
HTTP请求方式
GET
是否需要登录
true
请求数限制
true
请求参数
参数 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份 |
center_coordinates | false | string | 中心点坐标(用逗号分隔)(城市代码或中心点坐标至少选一项)会覆盖city |
city | false | string | 城市代码 (城市代码或中心点坐标至少选一项) |
coordinates | false | string | 坐标串,多组坐标间用分号分隔,如x0,y0;x1,y1... |
names | false | string | 名称串,以逗号分隔 |
size | false | string | size= width x height,地图宽度,默认240,地图高度,默认240 |
img_format | false | string | 输出格式图片格,包括png/jpg,,注意大小写,默认png |
zoom | false | string | 地图等级(1-17),如果不传,默认根据图上的加入的poi和线,自适应大小 |
px | false | string | 轴偏移方向,东移为正,西移为负,单位1为1/4的图片宽度,例如px=1,等于地图向右移动1/4的长度 |
py | false | string | 轴偏移方向,北移为正,南移为负,单位1为1/4的图片高度,例如px=1,等于地图向上移动1/4 |
icons | false | string | 用来表示需要加点的tip图片名(此值形式为105),每个点之间的图片用逗号分隔和names参数和xs,ys参数顺序对应描述一个点,图片规格12*12的 gif格式 |
font | false | string | 宋体,1,20,0xff0cc0,0xffffe0,1
含义对应关系如下: 宋体---- 字体 1---字体风格 20---字号 0xff0cc0-----字体颜色 0xffffe0-----字体背景 1------是否有背景色,0无,1有 |
lines | false | string | 画线的格式和坐标描述,添加一组线示例:lines=0x000000,2,116.32569,39.96682,116.12568,39.9671,116.32568,39.8671
参数顺序依次为: |
polygons | false | string | 画多边形,添加一组多边形示例:polygons=0x000000,1,1,50,116.32569,39.96682,116.12568,39.9671,116.32568,39.8671
参数顺序依次为: |
scale | false | enums | false或true,是否展示比例尺 |
traffic | false | enums | on或off,是否叠加事实交通地图 |
返回结果
返回生成的静态地图的图片地址
XML示例
<?xml version="1.0" encoding="UTF-8" ?> <geoResult> <url> http://202.108.5.66:8081/MapServerBM/maptemp/20114/817/1302253899522_20.png </url> </geoResult>
JSON示例
{"url":"http:\/\/202.108.5.66:8081\/MapServerBM\/maptemp\/20114\/817\/1302254393724_37.png"}
其它
PHP示例
需要开启PHP的cURL扩展
<?php //改为你的微博账号,用户名和密码之间用:隔开 $userPwd = 'user@sina.com:pwd'; //改为你微博应用的appkey $appkey = '0123456789'; $url = "http://api.t.sina.com.cn/location/base/get_map_image.xml?center_coordinates=116.3136,39.9824&zoom=12&img_format=png&coordinates=116.3136,39.98&names=hello&size=400x400&icons=105&px=1&traffic=on&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