地图画线,实现轨迹回放  

     //将经,纬度加入数组
    CLLocation *nowLocation = [[CLLocation alloc] initWithLatitude:coords.latitude longitude:coords.longitude];
     [rePlayArray addObject:nowLocation];
 
 
 
//直接调用就画线了
  [ self drawLineWithLocationArray:rePlayArray]; //rePlayArray加载的所有CLLocation
 
 
 
- ( void )drawLineWithLocationArray:( NSArray *)locationArray
{
     // create a c array of points.
     MKMapPoint* pointArray = malloc( sizeof (CLLocationCoordinate2D) * locationArray.count);
     
     // for(int idx = 0; idx < pointStrings.count; idx++)
     for ( int idx = 0; idx < locationArray.count; idx++)
     {
         CLLocation *location = [locationArray objectAtIndex:idx];
         CLLocationDegrees latitude  = location.coordinate.latitude;
         CLLocationDegrees longitude = location.coordinate.longitude;
         
         // create our coordinate and add it to the correct spot in the array
         CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
         MKMapPoint point = MKMapPointForCoordinate(coordinate);
         pointArray[idx] = point;
     }
     
     if (routeLine) {
         [_mapView removeOverlay:routeLine];
     }
     
     routeLine = [MKPolyline polylineWithPoints:pointArray count:locationArray.count];
     
     // add the overlay to the map
     if ( nil != routeLine) {
         [_mapView addOverlay:routeLine];
     }
     
     // clear the memory allocated earlier for the points
     free(pointArray);
}
 
 
 
 
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:( id <MKOverlay>)overlay {
     MKOverlayView* overlayView = nil ;
     
     if (overlay == routeLine)
     {
         //if we have not yet created an overlay view for this overlay, create it now.
         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 ;
}


你可能感兴趣的:( ,地图画线,实现轨迹回放)