CLLocation *nowLocation = [[CLLocation alloc] initWithLatitude:coords.latitude longitude:coords.longitude];
[rePlayArray addObject:nowLocation];
[
self
drawLineWithLocationArray:rePlayArray];
- (
void
)drawLineWithLocationArray:(
NSArray
*)locationArray
{
MKMapPoint* pointArray = malloc(
sizeof
(CLLocationCoordinate2D) * locationArray.count);
for
(
int
idx = 0; idx < locationArray.count; idx++)
{
CLLocation *location = [locationArray objectAtIndex:idx];
CLLocationDegrees latitude = location.coordinate.latitude;
CLLocationDegrees longitude = location.coordinate.longitude;
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
MKMapPoint point = MKMapPointForCoordinate(coordinate);
pointArray[idx] = point;
}
if
(routeLine) {
[_mapView removeOverlay:routeLine];
}
routeLine = [MKPolyline polylineWithPoints:pointArray count:locationArray.count];
if
(
nil
!= routeLine) {
[_mapView addOverlay:routeLine];
}
free(pointArray);
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(
id
<MKOverlay>)overlay {
MKOverlayView* overlayView =
nil
;
if
(overlay == routeLine)
{
routeLineView = [[MKPolylineView alloc] initWithPolyline:routeLine];
if
(current_type == _CURRENT_TRACK)
{
routeLineView.fillColor = [UIColor blueColor];
routeLineView.strokeColor = [UIColor blueColor];
}
else
{
routeLineView.fillColor = [UIColor redColor];
routeLineView.strokeColor = [UIColor redColor];
}
routeLineView.lineWidth = 6;
overlayView = routeLineView;
return
overlayView;
}
return
nil
;
}