HOME 生活记录运维/编程
作者/来源:yixinu.com
栏目:运维/编程
日期:2016-08-11 15:01:57

mysql算法是这样的

SELECT *, ROUND(6378.138*2*ASIN(SQRT(POW(SIN((22.299439*PI()/180-latitude*PI()/180)/2),2)+COS(22.299439*PI()/180)*COS(latitude*PI()/180)*POW(SIN((114.173881*PI()/180-longitude*PI()/180)/2),2)))*1000) AS juli FROM map ORDER BY juli DESC;



function gainNearby($longitude = '',$latitude = ''){
2 $sql= "SELECT *,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(( ? * PI()/180-latitude*PI()/180)/2),2)+COS( ? *PI()/180)*COS(latitude*PI()/180)*POW(SIN(( ? * PI()/180-longitude*PI()/180)/2),2)))*1000) AS juli FROM map WHERE longitude between ? - 0.5 and ? + 0.5  AND latitude between ? - 0.5 and ? + 0.5";
3 $query= $this->db->query($sql, array($latitude,$latitude,$longitude,$longitude, $longitude,$latitude,$latitude));
4 $result = $query->result_array();
5 return $result;
6 }




UKOBZ-QLMWX-IEF4G-7WDPG-DMKH7-MRBGT

分享到:

Copyright © 2013-2014 yixinu.com 湘ICP备14004402号

QQ:316686606  Email: 316686606@qq.com