偶尔,我的MKMapView会显示蓝色污迹。 似乎与我手动重新调整大小和在地图上移动有关。 Iphone6 +和iPhone7 + Xcode 8
绘制蓝色路线的代码.....................
添加路线覆盖:
// Draw route line (Add data for map route from prev location to latest, if prev):
CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = GPS_location_file[ previous_record ]; // prev GPS
coordinateArray[1] = GPS_location_file[ new_record_index ]; // this latest GPS
// Sets MKPolyline routeLine to these 2 latest route points:
view_controller.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
//[view_controller.mapView.visibleMapRect:[view_controller.routeLine boundingMapRect]]; //If you want the route to be visible
// Adds new overlay with latest two route lines to map:
[view_controller.mapView addOverlay: view_controller.routeLine];
代表请求在MKMAPVIEW上显示路线:
(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id)overlay { printf(" \ n%s:", FUNCTION ); // if(overlay == self.routeLine) // { // printf(" \ n self.routeLine"); // if(nil == self.routeLineView) // { // printf(" \ n nil == self.routeLineView");
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithOverlay:overlay];
renderer.strokeColor = [UIColor blueColor];
renderer.lineWidth = 4.0;
return renderer;
//} //返回self.routeLineView; //} //返回nil; }