开发者

query the color of the MKpolygon on where the user is

开发者 https://www.devze.com 2023-01-31 15:09 出处:网络
I wa开发者_C百科s wondering if there was a way to query what color my MKPolygon layer is, if the users locations is on top of it.

I wa开发者_C百科s 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


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.


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;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消