나는 3 단계로이 문제를 해결하려고한다.
// 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];
}
2 단계.
- (MKOverlayView*)mapView:(MKMapView*)theMapView
viewForOverlay:(id <MKOverlay>)overlay
{
MKPolylineView *overlayView = [[MKPolylineView alloc]
initWithOverlay:overlay];
overlayView.lineWidth = 3;
overlayView.strokeColor = [[UIColor blueColor]colorWithAlphaComponent:0.5f];
// overlayView.fillColor = [[UIColor purpleColor] colorWithAlphaComponent:0.1f];
path = overlayView.path;
return overlayView;
}
3 단계 : CGPathRef
에 MKPolylineView
변환하면 두 점 사이의 경로를 생성하기 위해 구현해야합니다 CGPathRef
{
CGPathRef path;
}
이 방법 형식의 클래스 변수를 만들고 확인하는 사용자 정의 방법을 만들기 포인트가 CG 패스에 있는지 여부
- (BOOL)userRouteIntersectsGoogleRoute
{
// Loop through all CGPoints
for(CGPoint point in self.userCoordinatePoints)
{
BOOL val = CGPathContainsPoint(path, NULL, point);
if(val)
{
return YES;
}
}
return NO;
}
사용자가 그 행 (위치 서비스를 통한 실제 위치) 또는 사용자에게 길 찾기를 허용하고 이러한 길의 경로가 특정 줄을 통과하는지 알아 내려고 시도하고 있습니까? –
@TimBodeit 사용자가 줄을 넘었는지 찾아야합니다 (예 : 마무리 줄을 통과 한 경우) – ghostrider