热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MKMapViewiOS8中为什么不显示MKCircle?-WhyMKCircleisnotdisplayedonMKMapViewiOS8

Icreatenewoverlayslikethis:我创建这样的新覆盖:MKCircle*circle[MKCirclecircleWithCenterCoordinate

I create new overlays like this:

我创建这样的新覆盖:

MKCircle *circle = [MKCircle circleWithCenterCoordinate:region.coordinate radius:region.radius];
[self.mapView addOverlay:circle];

also I implemented delegate method:

我还实现了委托方法:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id)overlay {
    MKCircleRenderer *circleRenderer = [[MKCircleRenderer alloc] init];
    circleRenderer.fillColor = [UIColor greenColor];
    circleRenderer.alpha = 1.f;
    return circleRenderer;
}

both parts of code are called, mapView != nil at that moment, it's delegate set, but I cannot see the circle on my map.

代码的两个部分都被调用,mapView != nil,它是委托集,但是我看不到地图上的圆。

What am I doing wrong?

我做错了什么?

2 个解决方案

#1


3  

Rather than init, call the MKCircleRenderer method initWithCircle.

而不是init,调用MKCircleRenderer方法initWithCircle。

Obviously, make sure the delegate of the map view is set, that your code that adds the overlay and that instantiates the renderer is called at all, etc., but initWithCircle is the likely culprit.

显然,要确保map视图的委托已经设置,您添加叠加和实例化渲染器的代码已经被调用,等等,但是initWithCircle很可能是罪魁祸首。

#2


7  

As per @Rob suggestion you need to init MKCircleRenderer using other method initWithCircle.

按照@Rob的建议,您需要使用其他方法initWithCircle初始化MKCircleRenderer。

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id)overlay {
    MKCircleRenderer *circleRenderer = [[MKCircleRenderer alloc] initWithCircle:overlay];
    circleRenderer.fillColor = [UIColor greenColor];
    circleRenderer.alpha = 1.f;
    return circleRenderer;
}

Also make sure that fence distance is proper enough to visible the circle in map.

还要确保栅栏的距离足够在地图上显示圆形。

For example:

例如:

CLLocationDistance fenceDistance = 100000;
MKCircle *circle = [MKCircle circleWithCenterCoordinate:region.coordinate radius:fenceDistance];
[self.mapView addOverlay:circle];

推荐阅读
author-avatar
壹起等绿灯
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有