gpt4 book ai didi

iOS - 确定坐标是否在 GMSPolyline 内

转载 作者:行者123 更新时间:2023-12-01 19:52:50 25 4
gpt4 key购买 nike

我已经在使用GMSGeometryContainsLocation的方法了为了确定坐标(来自点击用户)是否在 GMSPolygon 内,但我不能让它适用于 GMSPolyline。

-(void) didTapOnPolyline:(CLLocationCoordinate2D)coordinate andMap:(GMSMapView *)mapView {
if (_pathVS != nil) {
for (id key in _pathVS) {
if (GMSGeometryIsLocationOnPath(coordinate, [_pathVS objectForKey:key], YES)) {
_myMarker = [GMSMarker markerWithPosition:coordinate];
_myMarker.opacity = 1.f;
// _myMarker.icon = [UIImage imageNamed:@"marker-maps"];

_myMarker.map = mapView;
_myMarker.userData = key;
[_mapView setSelectedMarker:_myMarker];
}
}
}
}

我从触发的委托(delegate)方法中调用此方法:
-(void) mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
if (_myMarker)
_myMarker.map = nil;

[self didTapOnPolygon:coordinate andMap:mapView];
[self didTapOnPolyline:coordinate andMap:mapView];
}

最佳答案

如果点击点不在折线上,则 GMSGeometryIsLocationOnPath条件永远不会返回真。所以你必须使用 GMSGeometryIsLocationOnPathTolerance
谷歌地图 SDK 文档说

A point that is not equal to a vertex is on one side or the other of any path segment -- it can never be "exactly on the border"


BOOL GMSGeometryIsLocationOnPathTolerance (CLLocationCoordinate2D point, GMSPath *path, BOOL    geodesic, CLLocationDistance tolerance)

返回点是在路径上还是在路径附近,在以米为单位的指定容差范围内。

关于iOS - 确定坐标是否在 GMSPolyline 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44776414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com