iOS中的KMLViewer

时间:2013-02-12 07:25:26

标签: ios coordinates kml polygon

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

1 个答案:

答案 0 :(得分: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));
}