查询用户所在位置的 MKpolygon 的颜色

发布于 2024-10-07 17:56:14 字数 61 浏览 0 评论 0原文

我想知道是否有办法查询我的 MKPolygon 图层的颜色(如果用户位置位于其顶部)。

谢谢

I was wondering if there was a way to query what color my MKPolygon layer is, if the users locations is on top of it.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个少女永远怀春 2024-10-14 17:56:30

当您的 MKMapView 委托收到用户位置更新时,您可以循环遍历叠加层并查看用户位置是否位于任何叠加层的边界地图矩形内。在叠加层上,只需添加可用于查找颜色的“颜色”属性。

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    for (MyOverlayClass* overlay in mapView.overlays)
    {
        MKMapPoint userPoint = MKMapPointForCoordinate(userLocation.location.coordinate);
        if ( MKMapRectContainsPoint(overlay.boundingMapRect, userPoint) ) 
        {
            UIColor* userInColor = overlay.color;
        }
    }
}

When your MKMapView delegate receives a user location update you can loop through your overlays and see if the users location is inside the bounding map rect for any of the overlays. On your overlay, just add a "color" property that you can use to find the color.

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    for (MyOverlayClass* overlay in mapView.overlays)
    {
        MKMapPoint userPoint = MKMapPointForCoordinate(userLocation.location.coordinate);
        if ( MKMapRectContainsPoint(overlay.boundingMapRect, userPoint) ) 
        {
            UIColor* userInColor = overlay.color;
        }
    }
}
你是暖光i 2024-10-14 17:56:28

没有。不可能。十天前我遇到了同样的情况,我一直在网上搜索,但无法执行该功能。我认为苹果应该在未来的 iOS SDK 中为 MKOverlay 提供一些代表,用于多边形上的触摸事件。

Nope. No way.I was on the same situation ten days ago and i searched in web all along and couldnt do that functionality. I think apple should come up with some delegates on MKOverlay in future iOS SDK's for touch events on polygons.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文