0

我正在测试 Apple 的 KMLViewer 软件,我想知道是否可以使用它来查找 x,y 坐标所属的国家/地区。我的 KML 文件包含所有国家/地区的所有数据。(多边形,覆盖......)。

4

1 回答 1

0

如果您已经创建了MKPolygon叠加层,并且您MKMapView已经在 中创建了MKPolygonView视图mapView:viewForOverlay:,并且您只是想查看特定的点击手势MKPolygonView,我认为您可以执行以下操作:

- (void)handleTap:(UITapGestureRecognizer *)gesture
{
    BOOL success = NO;

    CGPoint location = [gesture locationInView:self.mapView];
    CLLocationCoordinate2D coordinate = [self.mapView convertPoint:location toCoordinateFromView:self.mapView];
    MKMapPoint mapPoint = MKMapPointForCoordinate(coordinate);

    for (id<MKOverlay> overlay in self.mapView.overlays)
    {
        MKOverlayView *overlayView = [self.mapView viewForOverlay:overlay];
        if ([overlayView isKindOfClass:[MKPolygonView class]])
        {
            MKPolygon *polygon = (MKPolygon *)overlay;
            MKPolygonView *polygonView = (MKPolygonView *)overlayView;
            CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint];
            if (CGPathContainsPoint([polygonView path], NULL, polygonViewPoint, NO))
            {
                NSLog(@"Overlay '%@' contains point %@", polygon.title, NSStringFromCGPoint(location));
                success = YES;
                break;
            }
        }
    }

    if (!success)
        NSLog(@"No overlays contained point %@", NSStringFromCGPoint(location));
}
于 2013-02-12T10:16:41.677 回答