I would try to solve this problem in three stages:
Step 1. Convert each track of the user track to CGPoint and save the array.
// in viewDidLoad locManager = [[CLLocationManager alloc] init]; [locManager setDelegate:self]; [locManager setDesiredAccuracy:kCLLocationAccuracyBest]; [locManager startPdatingLocation]; self.userCoordinatePoints = [NSMutableArray alloc]init]; - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { CLLocationCoordinate2D loc = [newLocation coordinate]; CGPoint *currentPoint = [self.mapView convertCoordinate:loc toPointToView:self.mapView]; // add points to array self.userCoordinatePoints addObject:currentpoint]; }
Step 2. Convert MKPolylineView to CGPathRef
Create a class variable of type CGPathRef
{ CGPathRef path; }
This method must be implemented to create a route between two points:
- (MKOverlayView*)mapView:(MKMapView*)theMapView viewForOverlay:(id <MKOverlay>)overlay { MKPolylineView *overlayView = [[MKPolylineView alloc] initWithOverlay:overlay]; overlayView.lineWidth = 3; overlayView.strokeColor = [[UIColor blueColor]colorWithAlphaComponent:0.5f];
Step 3. Create your own method to check if the point is in CGPath or not.
- (BOOL)userRouteIntersectsGoogleRoute { // Loop through all CGPoints for(CGPoint point in self.userCoordinatePoints) { BOOL val = CGPathContainsPoint(path, NULL, point); if(val) { return YES; } } return NO; }
source share