- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在城市上绘制多边形,以检查当前位置是否在该多边形内,我正在使用以下代码执行此操作:-
ArrayList<LatLng> polyLoc = new ArrayList<LatLng>();
polyLoc.add(new LatLng(24.643932, 46.297718));
polyLoc.add(new LatLng(24.695098, 46.555897));
polyLoc.add(new LatLng(24.921971, 46.476246));
polyLoc.add(new LatLng(25.147185, 46.366383));
polyLoc.add(new LatLng(25.155886, 47.249409));
polyLoc.add(new LatLng(24.929444, 47.346913));
polyLoc.add(new LatLng(24.691355, 47.106587));
polyLoc.add(new LatLng(24.449060, 47.219197));
polyLoc.add(new LatLng(24.293947, 46.973377));
polyLoc.add(new LatLng(24.641436, 46.299092));
我通过这种方式检查当前位置是否在这个多边形内:-
if (hasPermission() && gpsTracker.canGetLocation()) {
if (isPointInPolygon(new LatLng(gpsTracker.getLatitude(), gpsTracker.getLongitude()), polyLoc)) {
cash.setVisibility(View.VISIBLE);
cashIcon.setVisibility(View.VISIBLE);
} else {
cash.setVisibility(View.GONE);
cashIcon.setVisibility(View.GONE);
}
Log.d(TAG, "reservationDialog: " + gpsTracker.getLatitude() + gpsTracker.getLongitude());
}
这是我的 isPointInPolygon 方法:
private boolean isPointInPolygon(LatLng tap, ArrayList<LatLng> vertices) {
int intersectCount = 0;
for (int j = 0; j < vertices.size() - 1; j++) {
if (rayCastIntersect(tap, vertices.get(j), vertices.get(j + 1))) {
intersectCount++;
}
}
return ((intersectCount % 2) == 1); // odd = inside, even = outside;
}
private boolean rayCastIntersect(LatLng tap, LatLng vertA, LatLng vertB) {
double aY = vertA.latitude;
double bY = vertB.latitude;
double aX = vertA.longitude;
double bX = vertB.longitude;
double pY = tap.latitude;
double pX = tap.longitude;
if ((aY > pY && bY > pY) || (aY < pY && bY < pY)
|| (aX < pX && bX < pX)) {
return false; // a and b can't both be above or below pt.y, and a or
// b must be east of pt.x
}
double m = (aY - bY) / (aX - bX); // Rise over run
double bee = (-aX) * m + aY; // y = mx + b
double x = (pY - bee) / m; // algebra is neat!
return x > pX;
}
我不知道为什么它不起作用,我在这里错过了什么?
最佳答案
我不知道为什么你的代码不起作用。
但是你可以使用PolyUtil.containsLocation(new LatLng(纬度,经度), polyLoc, true)
如果位置在多边形之外,则返回 false。
关于android - 检查 Latlng 是否在多边形内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46091798/
我必须用小工具制作 map ,这些小工具从上一点获得电压。我的数据库中有纬度和经度的记录。我使用自定义图标和 windowInfo 在 map 上存储带有标记的小工具,但我想获取上一个点的纬度和经度,
我的任务是查找两个纬度和经度坐标之间的行驶距离。我在[此处][1]找到了此链接,但是,我不确定我是否正确实现了它,因为我收到了错误...... Invalid float: "" GeocodingL
我一直致力于 Android 中的 Google map 服务。我想知道是否有一个实用方法可以给出 LatLng 的方向关于另一个。 我想知道一个点是否在 南还是北 东方还是西方 或两者的组合,各取其
LATLNG 无法将参数类型“LatLng”分配给参数类型“LatLng” The argument type 'LatLng (where LatLng is defined in E:\flutt
目标 知道一个坐标点是否在另外两个坐标之间。 背景 我正在制作一个谷歌地图应用程序,我需要知道某个点是否在两个 LatLng 点(起点和终点)之间。 我正在寻找如下函数: var currentCoo
在行“Location.distanceBetween(LatLng.latitude, LatLng.longitude, circle.getCenter().latitude,circle.ge
我可以使用什么算法/公式来计算距离另一个 LatLng 点 5 米的 LatLng 点?我正在尝试编写一个带有 2 个 LatLng 参数的函数,并让它返回一个 LatLng,该 LatLng 距离第
使用文档示例,我尝试放大特定点。所以我这样做: var latlng = L.latLng(50.5, 30.5); $scope.map.setZoomAround(latlng); $scope.
我有 2 个列表。 double pointY[]={105.45526,105.57364,105.53505,105.45523,105.51962,105.77320} double point
假设我有一个关联的纬度/经度 + 名称的 HashMap,以及一个相同纬度/经度的单独 ArrayList,这些纬度/经度已按距离我当前位置最近的位置排序。如何将 HashMap 排序为与 Array
我需要查明某些 LatLng 是否在 Google map 圈内(其中之一:http://code.google.com/apis/maps/documentation/javascript/over
我正在尝试在当前位置设置标记,因此我尝试将 Location 转换为 LatLng 类: LatLng mCurrentPlace= new LatLng(location.getLatitude()
我正在 Flutter 中使用 Leaflet 完成我的第一个婴儿步骤,因此欢迎耐心和教程 URL 等。 我能找到的每一段示例代码都给了我这个错误: The method 'LatLng' isn't
因此,我开始在我的小应用程序中建立并运行我的 map ,当我尝试放入相机移动时,我遇到了一些小障碍。编译器似乎根本不喜欢 LatLng 类。它给了我这个。 The method LatLng(doub
我正在从 MainActivity 向名为 MapClass 的类发送 IntentService 调用。 MapClass 有一个名为 MapClassInner 的内部类,它计算用户的当前坐标。但
我创建了一个函数来返回纬度和经度。 问题是 alert('outside:') 在 geocoder.geocode 之前触发。 查看this similar example ,这个功能应该工作。
在我更改包名称之前,一切都在我的设备上正常工作...一旦更改 pkg,相机就不会移动到初始 latlng。此外,标记不会显示。 package com.vaishnavismeclass.divyad
我有List有位置(超过 2000 个位置)。每个位置有 100 米的距离。但是列表太大所以我想根据位置优先级过滤一些位置(比如访问最多的位置、著名位置、实体名称、城市名称或其他) 实际上,当用户移动
我在使用 latlng 变量在 Leaflet map 上创建新圆时遇到问题。 我有一个包含和输入半径的表单和一个包含几个位置的选择框,选项如下所示: Place Name 单击保存按钮时,将运行以下
我想在 touchmove 事件(传单 map )中获取触摸点的 LatLng。我没有找到解决这个问题的方法。有什么方法可以获取坐标吗? $(document).on('touchmove', '#m
我是一名优秀的程序员,十分优秀!