0

I have downloaded this code. I want to check whether the users current location belongs to any of the region. For that i have called following method but its always returning FALSE. Below is my code:

-(void)checkPoint
{
    CLLocationCoordinate2D mapCoordinate ;
    mapCoordinate.longitude=34.54664654;
    mapCoordinate.latitude=-117.05646;

    NSMutableArray *overlays = (NSMutableArray *)[HHLViewController usStatesAndTerritoryOverlays];

    MKMapPoint mapPoint = MKMapPointForCoordinate(mapCoordinate);
    for (int i=0; i<[overlays count]; i++)
    {

        MKOverlayView *overlayview = (MKOverlayView *)[self.stateMapView viewForOverlay:[overlays objectAtIndex:i]];


         MKPolygonView *polygonView =[[MKPolygonView alloc] initWithOverlay:overlayview.overlay];


        CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint];

        BOOL mapCoordinateIsInPolygon =
        CGPathContainsPoint(polygonView.path, NULL, polygonViewPoint, NO);

        NSLog(@"polygon is inside %d",mapCoordinateIsInPolygon);
    }

}

My problem is i want always getting NO value in mapCoordinateIsInPolygon eventhough the point belongs to that region.

I dont want to display map so any other options are also welcomed.

Dhara
  • 4,093
  • 2
  • 36
  • 69
  • I do not much about the API's you are using, but I have implemented pointInsidePolygon before using this method: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html Also, see here for some throroughly explained solutions: http://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test – Ricardo Sanchez-Saez Jul 30 '13 at 12:53
  • sorry i misunderstood question check this link might be similor to your need http://stackoverflow.com/questions/4354130/how-to-determine-if-an-annotation-is-inside-of-mkpolygonview-ios – Nitin Gohel Jul 30 '13 at 12:57
  • @rsanchezsaez i have gone through that also but it was not helpful – Dhara Jul 31 '13 at 12:08

0 Answers0