Distance/distance point

跳转到: 导航, 搜索

目录

distance/distance_point

计算地图上两点之间的距离

URL

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

支持格式

XML/JSON

HTTP请求方式

GET


是否需要登录

true


请求数限制

true


请求参数

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

返回结果

JSON示例

{"distance":{"length":"123"},"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_point.json?x1=116.1111111&y1=39.1111111&x2=116.1111111&y2=39.1122222&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;
}
?>