ElasticSearch LBS检索

$data = Http\Request::get('poi/users/_search?', array(
	'query' => array(
		'match_all' => array(),
	),
	'filter' => array(
		'geo_distance' => array(
			'distance' => '10km',#10km以内
			"location" => array('lat' => $lat, 'lon' => $lon),
		),
	),
	'sort' => array(
		array(
			'_geo_distance' => array(
				"location" => array('lat' => $lat, 'lon' => $lon),
				"order" => "asc",#由近到远
				"unit" => 'm',#输出距离单位
				//"distance_type" => "plane",
			),
		),
	),
	'from' => 1,
	'size' => 100,
));

PHP计算两个经纬度点之间距离

// 单位为米
function st_distance($lng1, $lat1, $lng2, $lat2) {
	$radLat1 = deg2rad($lat1); //deg2rad()函数将角度转换为弧度
	$radLat2 = deg2rad($lat2);
	$radLng1 = deg2rad($lng1);
	$radLng2 = deg2rad($lng2);
	$a = $radLat1 - $radLat2;
	$b = $radLng1 - $radLng2;
	$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137 * 1000;
	return $s;
}

撸了个MySQL转PostgreSQL脚本

https://github.com/cevin/mysql2postgresql

1.为了最大兼容,字段用的都是character varying(varchar,char等)、numeric(mysql的int,bigint,smallint,float,double等).mysql的enum类型使用的是character varying check(field in array)
2.PostgreSQL系统保留字段为’ctid’,’cmax’,’xmax’,’xmin’,’tableoid’,’oid’。转换过程中冲突的自动改名加p前缀比如ctid=pctid