さて、私が抱えている問題は、iPhoneのコンパス方位によって駆動されるオーバーレイがあることです。コンパスの方位が変わるたびに、線は方位とともにマップを横切って移動する必要があります。2つのオーバーレイがあります。1つはコンパス用で、もう1つはもう1つです。コンパスオーバーレイのみを表示している場合は、変化に応じて線がちらつきますが、他の線を表示している場合は、ちらつきがなくなり、線がスムーズに動きます。
- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
SatFinderAppDelegate *appdel = (SatFinderAppDelegate *)[[UIApplication sharedApplication]delegate];
float s = [appdel.location floatValue];
if (overlay == self.headingline)
{
headinglineView = [[MKPolylineView alloc] initWithPolyline:self.headingline];
headinglineView.fillColor = [UIColor greenColor];
headinglineView.strokeColor = [UIColor greenColor];
headinglineView.lineWidth = 5;
return self.headinglineView;
}
if (overlay == self.routeLine)
{
if (s == 0) {
return routeLineView = nil;
}
routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
routeLineView.fillColor = [UIColor cyanColor];
routeLineView.strokeColor = [UIColor cyanColor];
routeLineView.lineWidth = 5;
if (ele < 0) {
routeLineView.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:12],
[NSNumber numberWithFloat:8],nil];
routeLineView.strokeColor = [UIColor redColor];
}
return routeLineView;
}
return nil;
}
..。
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
//line for heading
[self headinglineupdate];
}
...。
-(void)headinglineupdate
{
[map removeOverlay:self.headingline];
self.headingline = nil;
self.headingline = [MKPolyline polylineWithCoordinates:locations count:2];
[map addOverlay:headingline];
[headinglineView setNeedsDisplay];
[map setNeedsDisplay];
}