ios - 圆圈叠加层未显示在 map 上

标签 ios dictionary overlay

我正在尝试向 map 添加圆形叠加层,但它没有出现:

- (void) displayOverlayOnMap:(double) lat andlng: (double)  lng
{
    CLLocationCoordinate2D bostonCoord = CLLocationCoordinate2DMake(lat,lng);
    //add MKCircle overlay...
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:bostonCoord radius:1000];
   [self.mapView addOverlay:circle]; 
}

有人知道为什么它不显示吗?

最佳答案

这是一个例子..您还可以在苹果网站上找到一个使用多边形的例子:https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW15

或者你可以使用这个例子

Create overlay from user interaction on MKMapView?

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
        return;

    CGPoint touchPoint = [gestureRecognizer locationInView:mapView];    
    CLLocationCoordinate2D touchMapCoordinate = [mapView convertPoint:touchPoint toCoordinateFromView:mapView];

    //add pin where user touched down...
    MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
    pa.coordinate = touchMapCoordinate;
    pa.title = @"Hello";
    [mapView addAnnotation:pa];
    [pa release];

    //add circle with 5km radius where user touched down...
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:touchMapCoordinate radius:5000];
    [mapView addOverlay:circle];
}

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay 
{
    MKCircleView* circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease];
    circleView.fillColor = [UIColor redColor];
    return circleView;
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationIdentifier = @"Annotation";
    MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
    if (!pinView)
    {
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
        pinView.pinColor = MKPinAnnotationColorGreen;
        pinView.animatesDrop = YES;
    }
    else
    {
        pinView.annotation = annotation;
    }
    return pinView;
}

关于ios - 圆圈叠加层未显示在 map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9147414/

相关文章:

image - ffmpeg 缩放输入图像

android - android中的覆盖是什么?

ios - UITabBar 图标在 iPad 上偏离中心

ios - iPad 与 iPad Mini 用户代理

objective-c - 使用 UTF-8 时带有错误字符的 NSString

python - 构造字典时如何使用变量的值作为键

c++ - 可以在内部使用任何基本类型的 map

c# - 如果我只需要快速查找键而值无关紧要,我应该使用 C# 字典吗?

android - 删除所有覆盖

javascript - 坚持构建一个 Meteor 项目