数组(“lat”=>$lat+$dlat,“lng”=>$lng-$dlng),“右上”=>数组(“lat”=>$lat+$dlat,'lng'=>$lng+$dlng),'left-bottom'=>array('lat'=>$lat-$dlat,'lng'=>$lng-$dlng),'right-bottom'=>array('lat'=>$lat-$dlat,'lng'=>$lng+$dlng));}//计算附近五公里的经纬度范围//根据这个range,查询数据库中符合条件的店铺/**获取一定范围内的位置*/functiongetSiteData($lng,$lat,$userType){//使用这个函数计算出结果后,带入查询。$squares=$this->returnSquarePoint($lng,$lat);if($squares['left-top']['lng']>$squares['right-bottom']['lng']){$lngMin=$squares['右下角']['lng'];$lngMax=$squares['左上角']['lng'];}else{$lngMin=$squares['left-bottom']['lng'];$lngMax=$squares['right-top']['lng'];}if($squares['left-top']['lat']>$squares['right-bottom']['lat']){$latMin=$squares['right-bottom']['lat'];$latMax=$squares['left-top']['lat'];}else{$latMin=$squares['left-top']['lat'];$latMax=$squares['right-bottom']['lat'];}$where="lng<>0andlng>=$lngMinandlng<=$lngMaxandlat>=$latMinandlat<=$latMaxandstatus=1";if($userType){$where.="ANDtype=2";}else{$where.="ANDtype=1";}$site_info=M('Site')->field('id,address,lat,lng')->where($where)->select();return$site_info;}/***根据地理位置获取经纬度(Gaumap)*/functiongetLngLat(){//获取地址的经纬度//$latLng=addressToLatLng($address);$url="https://restapi.amap.com/v3/geocode/geo?address=".$address."&key=45f048d3ba68c3e4c1a80f38d9ab96a8";$result=file_get_contents($url);$data=json_decode($result,true);if($data['status']!=1){$this->ajaxReturn(array('code'=>404,'msg'=>$data['info']));}$location=explode(',',$data['geocodes']['0']['location']);$lat=$location['1'];$lng=$位置['0'];}
