Dynamic and visualized display of iOS map lines

Source: Internet
Author: User

Dynamic and visualized display of iOS map lines
I have encountered such a problem before, that is, to draw the distance between two points and display the line in the visible range. Below are some main code:

# Pragma mark-driving route retrieval-(void) onGetDrivingRouteResult :( BMKRouteSearch *) searcher result :( random *) result errorCode :( BMKSearchErrorCode) error {if (error = BMK_SEARCH_NO_ERROR) {// NSArray * array = [NSArray arrayWithArray: _ mapView. annotations]; [_ mapView removeAnnotations: array]; array = [NSArray arrayWithArray: _ mapView. overlays]; [_ mapView removeOverlays: array]; if (error = BMK_SEARCH_NO_ERROR) {BMKDrivingRouteLine * plan = (BMKDrivingRouteLine *) [result. routes objectAtIndex: 0]; // calculate the number of road sections in the route plan. int size = [plan. steps count]; int planPointCounts = 0; for (int I = 0; I <size; I ++) {BMKDrivingStep * transitStep = [plan. steps objectAtIndex: I]; if (I = 0) {RouteAnnotation * item = [[RouteAnnotation alloc] init]; item. coordinate = plan. starting. location; item. title = @ "Start Point"; item. type = 0; [_ mapView addAnnotation: item]; // Add start point annotation} else if (I = size-1) {RouteAnnotation * item = [[RouteAnnotation alloc] init]; item. coordinate = plan. terminal. location; item. title = @ "end"; item. type = 1; [_ mapView addAnnotation: item]; // Add start point annotation} // Add annotation node RouteAnnotation * item = [[RouteAnnotation alloc] init]; item. coordinate = transitStep. entrace. location; item. title = transitStep. entraceInstruction; item. degree = transitStep. direction * 30; item. type = 4; [_ mapView addAnnotation: item]; // planPointCounts + = transitStep. pointsCount; // ------------------------------------------------------------- if (I = 0) {// use the first coordinate point as the initial value minLat = plan. starting. location. latitude; maxLat = plan. starting. location. latitude; minLon = plan. starting. location. longpolling; maxLon = plan. starting. location. longpolling;} else {// compare and filter out the minimum latitude and maximum latitude. The minimum longitude and the maximum longitude minLat = MIN (minLat, transitStep. entrace. location. latitude); maxLat = MAX (maxLat, transitStep. entrace. location. latitude); minLon = MIN (minLon, transitStep. entrace. location. longpolling); maxLon = MAX (maxLon, transitStep. entrace. location. longpolling);} // -------------------------------------------------------------} [self setVisibleRegin]; // Add the path if (plan. wayPoints) {for (BMKPlanNode * tempNode in plan. wayPoints) {RouteAnnotation * item = [[RouteAnnotation alloc] init]; item = [[RouteAnnotation alloc] init]; item. coordinate = tempNode.pt; item. type = 5; item. title = tempNode. name; [_ mapView addAnnotation: item] ;}// track point BMKMapPoint * temppoints = new BMKMapPoint [planPointCounts]; int I = 0; for (int j = 0; j <size; j ++) {BMKDrivingStep * transitStep = [plan. steps objectAtIndex: j]; int k = 0; for (k = 0; k
 
  

-(Void) setVisibleRegin {// calculate the center point CLLocationCoordinate2D centCoor; centCoor. latitude = (CLLocationDegrees) (maxLat + minLat) * 0.5f); centCoor. longpolling = (CLLocationDegrees) (maxLon + minLon) * 0.5f); BMKCoordinateSpan span; // calculates the span of a geographical location. latitudeDelta = maxLat-minLat; span. longitudeDelta = maxLon-minLon; // obtain the data coordinate region BMKCoordinateRegion region = BMKCoordinateRegionMake (centCoor, span ); // The coordinate range of Baidu map is converted to the position of the relative view CGRect fitRect = [_ mapView convertRegion: region toRectToView: _ mapView]; // convert the location of the map view to the location of the map. BMKMapRect fitMapRect = [_ mapView convertRect: fitRect toMapRectFromView: _ mapView]; // set the visible range of the map to the location of the map where the data is located [_ mapView setVisibleMapRect: fitMapRect animated: YES];}
Thank you for your criticism !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.