1. <tfoot id='s6xnZ'></tfoot>
        <legend id='s6xnZ'><style id='s6xnZ'><dir id='s6xnZ'><q id='s6xnZ'></q></dir></style></legend>
      1. <i id='s6xnZ'><tr id='s6xnZ'><dt id='s6xnZ'><q id='s6xnZ'><span id='s6xnZ'><b id='s6xnZ'><form id='s6xnZ'><ins id='s6xnZ'></ins><ul id='s6xnZ'></ul><sub id='s6xnZ'></sub></form><legend id='s6xnZ'></legend><bdo id='s6xnZ'><pre id='s6xnZ'><center id='s6xnZ'></center></pre></bdo></b><th id='s6xnZ'></th></span></q></dt></tr></i><div id='s6xnZ'><tfoot id='s6xnZ'></tfoot><dl id='s6xnZ'><fieldset id='s6xnZ'></fieldset></dl></div>

        <small id='s6xnZ'></small><noframes id='s6xnZ'>

          <bdo id='s6xnZ'></bdo><ul id='s6xnZ'></ul>

        Android 地理围栏(多边形)

        时间:2023-09-02

        <small id='8Tfuq'></small><noframes id='8Tfuq'>

      2. <legend id='8Tfuq'><style id='8Tfuq'><dir id='8Tfuq'><q id='8Tfuq'></q></dir></style></legend>
          <bdo id='8Tfuq'></bdo><ul id='8Tfuq'></ul>
              <i id='8Tfuq'><tr id='8Tfuq'><dt id='8Tfuq'><q id='8Tfuq'><span id='8Tfuq'><b id='8Tfuq'><form id='8Tfuq'><ins id='8Tfuq'></ins><ul id='8Tfuq'></ul><sub id='8Tfuq'></sub></form><legend id='8Tfuq'></legend><bdo id='8Tfuq'><pre id='8Tfuq'><center id='8Tfuq'></center></pre></bdo></b><th id='8Tfuq'></th></span></q></dt></tr></i><div id='8Tfuq'><tfoot id='8Tfuq'></tfoot><dl id='8Tfuq'><fieldset id='8Tfuq'></fieldset></dl></div>

                  <tbody id='8Tfuq'></tbody>

                  <tfoot id='8Tfuq'></tfoot>
                1. 本文介绍了Android 地理围栏(多边形)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何从多个地理位置(经纬度值)创建多边形地理围栏.此外,如何跟踪用户是进入这个地理围栏区域还是在 android 上退出这个区域.

                  How to create Polygon Geofence from multiple geo locations(long,lat values) . Also how to track user is entering into this geofence region or exiting from this region on android.

                  推荐答案

                  地理围栏只是一个组成多边形的纬度/经度点的数组.获得纬度/经度点列表后,您可以使用点内多边形检查来查看某个位置是否在多边形内.

                  A geofence is simply an array of lat/long points that form a polygon. Once you have a list of lat/long points, you can use a point-inside-polygon check to see if a location is within the polygon.

                  这是我在自己的项目中用于对非常大的凹多边形(20K+ 顶点)执行多边形点检查的代码:

                  This is code I have used in my own projects to perform point-in-polygon checks for very large concave polygons (20K+ vertices):

                  public class PolygonTest
                  {
                      class LatLng
                      {
                          double Latitude;
                          double Longitude;
                  
                          LatLng(double lat, double lon)
                          {
                              Latitude = lat;
                              Longitude = lon;
                          }
                      }
                  
                      bool PointIsInRegion(double x, double y, LatLng[] thePath)
                      {
                          int crossings = 0;
                  
                          LatLng point = new LatLng (x, y);
                          int count = thePath.length;
                          // for each edge
                          for (var i=0; i < count; i++) 
                          {
                              var a = thePath [i];
                              var j = i + 1;
                              if (j >= count) 
                              {
                                  j = 0;
                              }
                              var b = thePath [j];
                              if (RayCrossesSegment(point, a, b)) 
                              {
                                  crossings++;
                              }
                          }
                          // odd number of crossings?
                          return (crossings % 2 == 1);
                      }
                  
                      bool RayCrossesSegment(LatLng point, LatLng a, LatLng b)
                      {
                          var px = point.Longitude;
                          var py = point.Latitude;
                          var ax = a.Longitude;
                          var ay = a.Latitude;
                          var bx = b.Longitude;
                          var by = b.Latitude;
                          if (ay > by)
                          {
                              ax = b.Longitude;
                              ay = b.Latitude;
                              bx = a.Longitude;
                              by = a.Latitude;
                          }
                              // alter longitude to cater for 180 degree crossings
                          if (px < 0) { px += 360; };
                          if (ax < 0) { ax += 360; };
                          if (bx < 0) { bx += 360; };
                  
                          if (py == ay || py == by) py += 0.00000001;
                          if ((py > by || py < ay) || (px > Math.max(ax, bx))) return false;
                          if (px < Math.min(ax, bx)) return true;
                  
                          var red = (ax != bx) ? ((by - ay) / (bx - ax)) : float.MAX_VALUE;
                          var blue = (ax != px) ? ((py - ay) / (px - ax)) : float.MAX_VALUE;
                          return (blue >= red);
                      }
                  }
                  

                  就程序流程而言,您需要后台服务进行位置更新,然后针对您的纬度/经度多边形数据执行此检查,以查看该位置是否在内部.

                  In terms of program flow, you will want a background service to do location updates and then perform this check against your lat/long polygon data to see if the location is inside.

                  这篇关于Android 地理围栏(多边形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:确定 iPhone 用户所在的国家 下一篇:Android - 如何获取当前位置(纬度和经度)?

                  相关文章

                  最新文章

                  <i id='GCiNO'><tr id='GCiNO'><dt id='GCiNO'><q id='GCiNO'><span id='GCiNO'><b id='GCiNO'><form id='GCiNO'><ins id='GCiNO'></ins><ul id='GCiNO'></ul><sub id='GCiNO'></sub></form><legend id='GCiNO'></legend><bdo id='GCiNO'><pre id='GCiNO'><center id='GCiNO'></center></pre></bdo></b><th id='GCiNO'></th></span></q></dt></tr></i><div id='GCiNO'><tfoot id='GCiNO'></tfoot><dl id='GCiNO'><fieldset id='GCiNO'></fieldset></dl></div>
                  <legend id='GCiNO'><style id='GCiNO'><dir id='GCiNO'><q id='GCiNO'></q></dir></style></legend>

                    <small id='GCiNO'></small><noframes id='GCiNO'>

                    • <bdo id='GCiNO'></bdo><ul id='GCiNO'></ul>
                  1. <tfoot id='GCiNO'></tfoot>