#pragma mark - - (void)drawTestLine { // test code : draw line between Beijing and Hangzhou CLLocation *location0 = [[CLLocation alloc] initWithLatitude:39.954245 longitude:116.312455]; CLLocation *location1 = [[CLLocation alloc] initWithLatitude:30.247871 longitude:120.127683]; NSArray *array = [NSArray arrayWithObjects:location0, location1, nil]; [self drawLineWithLocationArray:array]; } - (void)drawLineWithLocationArray:(NSArray *)locationArray { int pointCount = [locationArray count]; CLLocationCoordinate2D *coordinateArray = (CLLocationCoordinate2D *)malloc(pointCount * sizeof(CLLocationCoordinate2D)); for (int i = 0; i < pointCount; ++i) { CLLocation *location = [locationArray objectAtIndex:i]; coordinateArray[i] = [location coordinate]; } self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:pointCount]; [self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; [self.mapView addOverlay:self.routeLine]; free(coordinateArray); coordinateArray = NULL; } #pragma mark - MKMapViewDelegate - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id )overlay { if (overlay == self.routeLine) { if (nil == self.lineRender) { self.lineRender = [[MKPolylineRenderer alloc] initWithPolyline:self.routeLine]; self.lineRender.strokeColor = [UIColor redColor]; self.lineRender.lineWidth = 5.f; } return self.lineRender; } return nil; }