相关疑难解决方法(0)

在iOS7中检测MKOverlay上的触摸(MKOverlayRenderer)

我有一个可能有数百个多边形的MKMapView.iOS7上假设使用MKPolygon和MKPolygonRenderer.

我需要的是一种对用户触摸其中一个多边形的方式.它们代表地图上具有一定人口密度的区域.在iOS6上,MKOverlay被绘制为MKOverlayViews,因此触摸检测更直接.现在使用渲染器我真的不明白这是怎么做的.

我不确定这会有所帮助甚至是相关的,但作为参考,我会发布一些代码:

这会使用mapData将所有MKOverlay添加到MKMapView.

-(void)drawPolygons{
    self.polygonsInfo = [NSMutableDictionary dictionary];
    NSArray *polygons = [self.mapData valueForKeyPath:@"polygons"];

    for(NSDictionary *polygonInfo in polygons){
        NSArray *polygonPoints = [polygonInfo objectForKey:@"boundary"];
        int numberOfPoints = [polygonPoints count];

        CLLocationCoordinate2D *coordinates = malloc(numberOfPoints * sizeof(CLLocationCoordinate2D));
        for (int i = 0; i < numberOfPoints; i++){
            NSDictionary *pointInfo = [polygonPoints objectAtIndex:i];

            CLLocationCoordinate2D point;
            point.latitude = [[pointInfo objectForKey:@"lat"] floatValue];
            point.longitude = [[pointInfo objectForKey:@"long"] floatValue];

            coordinates[i] = point;
        }

        MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coordinates count:numberOfPoints];
        polygon.title = [polygonInfo objectForKey:@"name"];
        free(coordinates);
        [self.mapView addOverlay:polygon];
        [self.polygonsInfo setObject:polygonInfo forKey:polygon.title]; …
Run Code Online (Sandbox Code Playgroud)

touch mapkit mkmapview ios mkoverlay

24
推荐指数
3
解决办法
7309
查看次数

标签 统计

ios ×1

mapkit ×1

mkmapview ×1

mkoverlay ×1

touch ×1