我已经在使用方法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];
}
}
}
}
我从触发的委托方法调用此方法:
-(void) mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
if (_myMarker)
_myMarker.map = nil;
[self didTapOnPolygon:coordinate andMap:mapView];
[self didTapOnPolyline:coordinate andMap:mapView];
}
答案 0 :(得分:2)
如果抽头点不完全在折线上,那么GMSGeometryIsLocationOnPath
条件将永远不会返回true。所以你必须使用GMSGeometryIsLocationOnPathTolerance
Google Map SDK文档说
一个不等于顶点的点位于任何路径段的一侧或另一侧 - 它永远不会“完全位于边界”
BOOL GMSGeometryIsLocationOnPathTolerance (CLLocationCoordinate2D point, GMSPath *path, BOOL geodesic, CLLocationDistance tolerance)
返回点位于路径上或路径附近,在指定的公差范围内(以米为单位)。