IOS version: Baidu map SDK displays a set of pins in full view, iossdk
IOS Baidu map SDK displays a set of pins in full view
Beautiful Life of the sun and fire god (http://blog.csdn.net/opengl_es)
This article follows the "signature-non-commercial use-consistency" creation public agreement
Reprinted please keep this sentence: Sun huoshen's beautiful life-this blog focuses on Agile development and mobile and IOT device research: iOS, Android, Html5, Arduino, pcDuino, otherwise, this blog post is rejected or reprinted. Thank you for your cooperation.
Refer to the following two link articles:
Http://www.bkjia.com/IOSjc/817431.html
Http://yang120jun.blog.51cto.com/3199830/1087548
But still cannot be scaled correctly. The Baidu map method used is:
/*** Set the display range of the current map and use the Cartesian coordinate system to represent * @ param mapRect the MAP range to be set, use the Cartesian coordinate system to indicate whether * @ param animate uses animation effects */-(void) setVisibleMapRect :( BMKMapRect) mapRect animated :( BOOL) animate;
After repeated trials, the following problems were found:
1. After processing by the first address, adaptive conversion still needs to be performed in the second address;
2. If the coordinates span an hour, the loaded map is converted to a very high zoom level, and the map does not display the content. Therefore, the latency scaling is required, which is 0.1 seconds, the latency of 0.08 seconds cannot be seen in the scaling process;
The basic information is as follows:
[self performSelector:@selector(delayZoom) withObject:nil afterDelay:0.08];
-(Void) delayZoom {BMKCoordinateRegion region = [self generateRegion: _ annotationsArray]; // adapt to the region = [_ mapView regionThatFits: region] displayed in the current map window; // The coordinate range of Baidu map is converted to the position of the relative view CGRect fitRect = [_ mapView convertRegion: region toRectToView: _ mapView]; // convert the map view position to the map position 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];}
To prevent the content of the above two links from evaporation in the near future, make a record below
----------------------------------------------------------
IOS dynamically displays the data in a visible range based on the coordinate region of the coordinate data point.
Popularity 5 comment 74
Author:Gzl1163 TA follow MP3/MP4, QQ login, 12:06:55 views 15618 times
After marking many points on a map, you can set the center point of the map, but the scaling level is a bit difficult to use,
Therefore, it is necessary to dynamically calculate based on the coordinate region of the coordinate data point, and display all the points in the visible range of the map.
Directly run the Code:
// Clear the views and data of coordinate data [_ bMapView removeAnnotations: _ mapAnnotations]; [_ mapAnnotations removeAllObjects]; [_ carPointArray removeAllObjects]; // declare the filtering of the location and region of the coordinate data during resolution, including the minimum and maximum CLLocationDegrees minLat of longitude and latitude; CLLocationDegrees maxLat; CLLocationDegrees minLon; CLLocationDegrees maxLon; // parse the data for (int I = 0; I <rows. count; I ++) {NSDictionary * row = [rows objectAtIndex: I]; coordinate model class * item = [[Coordinate model class alloc] initWithJson: row]; if (item. vehicleNo & [item. vehicleNo length]> 0) {annotation model class * annotation = [[annotation model class alloc] init]; annotation. coordinate = item. baiduCoordinate; annotation. item = item; [_ mapAnnotations addObject: annotation]; [_ bMapView addAnnotation: annotation]; [annotation release]; if (I = 0) {// use the first coordinate point as the initial value minLat = item. baiduCoordinate. latitude; maxLat = item. baiduCoordinate. latitude; minLon = item. baiduCoordinate. longpolling; maxLon = item. baiduCoordinate. longpolling;} else {// compare and filter out the minimum latitude and maximum latitude. The minimum longitude and the maximum longitude minLat = MIN (minLat, item. baiduCoordinate. latitude); maxLat = MAX (maxLat, item. baiduCoordinate. latitude); minLon = MIN (minLon, item. baiduCoordinate. longpolling); maxLon = MAX (maxLon, item. baiduCoordinate. longpolling);} [_ carPointArray addObject: item];} [item release];} // dynamic region based on coordinate data, to determine the display center and zoom level of the map if (_ carPointArray. count> 0) {// 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 = [_ bMapView convertRegion: region toRectToView: _ bMapView]; // convert the location of the map view to the location BMKMapRect fitMapRect = [_ bMapView convertRect: fitRect toMapRectFromView: _ bMapView]; // set the visible range of the map to the location of the map where the data is located [_ bMapView setVisibleMapRect: fitMapRect animated: YES];}
Supplement:
MKMapRect zoomRect = MKMapRectNull;for (id <MKAnnotation> annotation in mapView.annotations) { MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate); MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0); if (MKMapRectIsNull(zoomRect)) { zoomRect = pointRect; } else { zoomRect = MKMapRectUnion(zoomRect, pointRect); }}[mapView setVisibleMapRect:zoomRect animated:YES];
----------------------------------------------------------
Create and locate a map based on the specified longitude and latitude
// Map border implementation
UIView * view = [[UIView alloc] initWithFrame: CGRectMake (10,120,300,240)];
View. layer. cornerRadius = 12;
View. backgroundColor = [UIColor whiteColor];
View. layer. masksToBounds = YES;
[Self. view addSubview: view];
[View release];
// Add a map
Map = [[[MKMapView alloc] initWithFrame: view. bounds] autorelease];
Map. showsUserLocation = YES;
Map. mapType = MKMapTypeStandard; // map style
[View addSubview: map];
// Converts the passed longitude and latitude to doubel
Double fourth = [_ fourth doubleValue];
Double fourth1 = [_ four2doublevalue];
// Set it to a device and a specified longitude and latitude.
CLLocationCoordinate2D coords = CLLocationCoordinate2DMake (fourth, four22 );
// Zoom level
Float zoomlevels = 0.02;
MKCoordinateRegion region = MKCoordinateRegionMake (coords, MKCoordinateSpanMake (zoomLevel, zoomLevel ));
[Map setRegion: [map regionThatFits: region] animated: YES];