Distance/distance po li

跳转到: 导航, 搜索

目录

distance/distance_po_li

计算(x,y)到线的最近距离


URL

http://api.t.sina.com.cn/location/distance/distance_po_li.(json%7Cxml)


支持格式

XML/JSON


HTTP请求方式

GET

是否需要登录

true


请求数限制

true


请求参数

参数 必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份
x1 true float 起点坐标x1
y1 true float 起点坐标y1
xs true float 线的x坐标集合
ys true float 线的y坐标集合


返回结果

JSON示例

{"distance":{"length":"111","list":{"seg":[{"x":"116.1111111","y":"39.1122222"},{"x":"118.23321","y":"40.23323"}]},"list_attr":{"type":"list"}},"distance_attr":{"versionname":"1.0.7.2"}}


其它

PHP示例

需要开启PHP的cURL扩展

<?php
//改为你的微博账号,用户名和密码之间用:隔开
$userPwd = 'user@sina.com:pwd';
//改为你微博应用的appkey
$appkey = '0123456789';

$url = "http://api.t.sina.com.cn/location/distance/distance_po_li.xml?x1=116.1111111&y1=39.1111111&xs=116.1111111,118.23321&ys=39.1122222,40.23323&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;
}
?>