<?php

/**
* @name 围栏算法,判断一个坐标,是否在围栏里面.如:['113.664673,34.810146','113.681667,34.796896','113.69231,34.794711','113.702009,34.809159']
* @author macnie <mac@lenmy.com>
* @param array $fences 围栏,是一组坐标数组 如:113.674458,34.804719
* @param string $point 要判断的坐标
* @return bool
*/
function in_fences($fences, $point) {
$nvert = count($fences);
$vertx = [];
$verty = [];
list($testy, $testx) = explode(',', $point);
foreach ($fences as $r) {
list($lng, $lat) = explode(',', $r);
$vertx[] = $lat;
$verty[] = $lng;
}
$i = $j = $c = 0;
for ($i = 0, $j = $nvert - 1; $i < $nvert; $j = $i++) {
if (( ($verty[$i] > $testy) != ($verty[$j] > $testy) ) &&
($testx < ($vertx[$j] - $vertx[$i]) * ($testy - $verty[$i]) / ($verty[$j] - $verty[$i]) + $vertx[$i]))
$c = !$c;
}
return $c;
} //围栏map数据
$fences=[
'113.626809,34.75027',
'113.630975,34.752162',
'113.626102,34.753941'
];
$p="113.633093,34.751396"; //当前的位置
$res = in_fences($fences,$p);
var_dump($res);

  亲测有效

最新文章

  1. iOS UIApplication sharedapplication用法
  2. 可扩容分布式session方案
  3. IOS JSON
  4. c++中级 STL基础学习(二)
  5. Android笔记: Android版本号
  6. Oracle PO - 模块一揽子采购协议小结
  7. MVC神韵---你想在哪解脱!(十)
  8. onAttachedToWindow () 和 onDetachedFromWindow () ; 以及更新视图的函数ondraw() 和dispatchdraw()的区别
  9. ssh链接云主机的一些笔记
  10. How difficult is it to create a JavaScript framework?
  11. 各种异常 及异常类和Object类
  12. Intellij IDEA 插件开发之自建插件仓库
  13. VS2010+WPF+LINQ for MySQL
  14. STM32F1xx寄存器版库
  15. C# System.Collections.SortedList
  16. 虚拟机中安装完 CentOS7minimal 版本后无法联网的问题
  17. linux文件名匹配——通配符使用
  18. 使用JS实现俄罗斯方块游戏
  19. 通俗易懂讲解happens-before原则
  20. cargo rust 包管理工具

热门文章

  1. Thinkphp解决phpExcel导出数据量大导致内存溢出
  2. github骚操作
  3. EF Core的级联删除
  4. js同步和异步
  5. go module 设置
  6. 解决chrome没有允许添加flash的问题
  7. springboot升级2.0 fastjson报错? 2.0以上应该怎么整合fastjson?
  8. 使用python下载图片(福利)
  9. EasyUI中取的DataGrid中选中行数据
  10. linux(1)