开发者

query the color of the MKpolygon on where the user is

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜