IOS Baidu maps POI detailed search and path planning (with Demo)

POI (Point of Interest), the Chinese can be translated as “point of interest”. In the geographic information system, a POI can be a house, a shop, a mailbox, a bus station, etc..

Baidu maps iOS SDK provides bus transfer, driving, riding and walking 4 types of line planning for developers, according to the different schemes can also choose “the shortest time”, “the shortest distance” strategy to complete the final line planning. Developers can freely use according to their actual business needs.

I would like to look at this blog before you should go to the Baidu map developer documentation, the first two paragraphs are nonsense, but since it is the function of the blog point, or write it out.
Please download the Demo friends as far as possible to replace the Baidu appKey and project boundID, in order to facilitate some of my friends, I will not delete, the project can be run directly.

No picture no truth!

POI retrieval

IOS Baidu maps POI detailed search and path planning (with Demo)
Untitled,.Gif

Route planning

IOS Baidu maps POI detailed search and path planning (with Demo)
Untitle,.Gif

UI is my project on the shelves, in order to facilitate the blog and write demo I will drag directly into the.

Baidu map integration is very simple, in accordance with the development of the document a few minutes to get it, I do not copy, but the record may be a few problems where the bar.
1 Privacy – Location Always Usage Description plist.info GPS
2 LSApplicationQueriesSchemes requests to use if you need to transfer from the need to join the Baidu maps
display name plist.info Bundle 3, and it is necessary to
4 this file uses the c++ code, please make sure that the file extension to the.Mm
POI
details: the first step: setting AppKey in Appdelegate.m.

- (BOOL) application: (UIApplication * application) didFinishLaunchingWithOptions: (NSDictionary *) launchOptions [[UIWindow alloc] initWithFrame:[UIScreen {self.window = mainScreen].bounds]; HouseMapTootsViewController = *vc + HouseMapTootsViewController alloc] init]; vc.latitude = 31.976; vc.longitude = 118.71; UINavigationController = *navi [[UINavigationController alloc] initWithRootViewController:vc]; / / configuration of Baidu map [self configurationBMKMap]; self.window.rootViewController = Navi; [self.window makeKeyAndVisible]; return YES; #pragma mark} - Baidu map - (void) configurationBMKMap {/ / to use Baidu maps, please start BaiduMapManager _mapManager = [[BMKMapManager alloc] init]; BOOL RET = [_mapManager "appkey" generalDelegate:self]; if ((RET) {NSLog (@ "manager start failed!");}}

The second step: complete agent

#pragma mark - BMKGeneralDelegate - (void) onGetNetworkState: (int iError) {if (0 = = iError) {NSLog (@ "networking success");}else {NSLog ("onGetNetworkState%d", @ iError);}} - (void) onGetPermissionState: (int) iError if (0 = = {{NSLog (iError) "@ authorization success");}else {NSLog ("onGetPermissionState%d", @ iError);}}

The third step: to create a Baidu map, open the user position (behind the route planning needs). And add a pin that is the central point of your search.

Self.mapView = [[BMKMapView alloc] initWithFrame:CGRectMake (0, 40+64, kScreenWidth, kScreenHeight - 40 - 64)]; [self.view addSubview:self.mapView]; [self.view addSubview:self.planView]; self.locService [[BMKLocationService alloc] = init]; self.mapView.delegate = self; self.locService.delegate = self; / / orientation mode cannot be used to follow, otherwise it is not the center of the map pins [self.mapView setZoomLevel:16]; self.mapView.showMapScaleBar = YES; self.mapView.userTrackingMode = BMKUserTrackingModeNone; self.mapView.showsUserLocation = YES; [self.locService startUserLocationService]; CLLocationCoordinate2D coor; coor.latitude = self.latitude; coor.longitude = self.longitude; If (self.pointAnnotation = = Nil) {/ / self.pointAnnotation = [[YLAnnotationView custom pin alloc]init]; self.pointAnnotation.coordinate = coor; self.pointAnnotation.title = @ "listings"; self.pointAnnotation.subtitle = @ "click to go here"; self.pointAnnotation.image [UIImage imageNamed:@ = "homelocation"]}; [self.mapView addAnnotation:self.pointAnnotation]; / / set the center point [self.mapView setCenterCoordinate:coor]; / / self.poiSearch.delegate = self retrieval facilities add add; / / pin surrounding the retrieval of self.option.location = coor; self.option.pageIndex = 0; self.option.pageCapacity = 20; self.option.radius = 1500;

The fourth step: click on the event to initialize the search object, Demo I define a topView used to do a different Click to distinguish.

#pragma mark - YLSelectorItemViewDelegate - (void) didSelectedItems: (NSInteger) item {CLLocationCoordinate2D coor; coor.latitude = self.latitude; coor.longitude = self.longitude; self.seletItem = item; self.isFirst = YES; if (item = = 1) {self.option.keyword = @ "delicacy"; BOOL flag = [self.poiSearch poiSearchNearBy:self.option]; if (flag) {NSLog (@ "around search send");}else {NSLog (@ "around search failed to send");}}else if (item = = 2) {self.option.keyword = @ "supermarket"; BOOL flag1 = [self.poiSearch poiSearchNearBy:self.option]; if (flag1) {NSLog (@ "around search sent successfully;}else) {}} Else if (item = = 3) {self.option.keyword = @ "ATM"; BOOL Flag2 = [self.poiSearch poiSearchNearBy:self.option]; if (Flag2) {NSLog (@ "around search successfully sent");}else {NSLog (@ "around search failed to send");}}else if (item = = 4) {self.option.keyword = @ "shopping" BOOL flag3 = [self.poiSearch; poiSearchNearBy:self.option]; if (flag3) {NSLog (@ "around search successfully sent");}else {NSLog (@ "around search failed to send");}}}

Step fifth: click after entering the agent, first remove the pins on the screen, because here I am still need to display the housing pin, here I made a deal with preserved in the for loop to get all objects in list, the object is for us to the surrounding information, but not details, details of the target object is the need to get the UID again to search (search and retrieval are common here details of Baidu forcibly separated, may be in traffic or modular about it). Then you must create a search object again, this time the for cycle will appear a detailed search, so we can do things in the details of the agent.

/ / PoiSearchDeleage handling callback results - (void) onGetPoiResult: (BMKPoiSearch * searcher) result: (BMKPoiResult *) poiResultList errorCode: (BMKSearchErrorCode error) {/ / clear screen except listings of all annotation NSMutableArray array = [NSMutableArray * arrayWithArray:self.mapView.annotations]; / / the Housing Preservation download [array removeObjectAtIndex:0]; [self.mapView removeAnnotations:array]; array = [[NSArray arrayWithArray:self.mapView.overlays] mutableCopy]; [self.mapView removeOverlays:array]; if (error = = BMK_SEARCH_NO_ERROR) {for (int i = 0; I < poiResultList.poiInfoList.count; i++) {BMKPoiInfo *poi = [poiResultList.poiInfoList objectAtIndex:i]; / / custom BMKPoiDetailSearchOption *option alloc] init] pin = [[BMKPoiDetailSearchOption; option.poiUid = poi.uid; BMKPoiSearch = *se [[BMKPoiSearch alloc] init]; se.delegate = self; / / put all the POI into an array, for the final release of [self.poiDetails, avoid circular reference; addObject:se]; [se poiDetailSearch:option] else;}} if (error = = BMK_SEARCH_AMBIGUOUS_KEYWORD) {NSLog (@ "search term is ambiguous");} else {/ / all judgment... }}

Details agent, here I need different pin pictures, do a deal

The details surrounding the search agent / / - (void) onGetPoiDetailResult: (BMKPoiSearch * searcher) result: (BMKPoiDetailResult *) poiDetailResult errorCode: (BMKSearchErrorCode) errorCode {CLLocationCoordinate2D houseCoor; houseCoor.latitude = self.latitude; houseCoor.longitude = self.longitude; if (errorCode = = BMK_SEARCH_NO_ERROR) {YLAnnotationView *item = [[YLAnnotationView alloc] init]; item.coordinate = poiDetailResult.pt; switch (self.seletItem) {case 1: item.image = [UIImage imageNamed:@] "food"; item.subtitle stringWithFormat:@ = [NSString "price:%.2f", poiDetailResult.price]; break; case 2: item.image = [UIImage imageNam Ed:@ "supermarket"]; item.subtitle = poiDetailResult.address; item.image = break; case 3: [UIImage imageNamed:@ "ATM"]; item.subtitle = poiDetailResult.address; item.image = break; case 4: [UIImage imageNamed:@ "shoping"]; item.subtitle = poiDetailResult.address; break; default: break;} item.title = poiDetailResult.name; / / add a judgment, first came in sets the center point, not every mobile center, or POI period will not drag the map. If (self.isFirst) {[self.mapView setCenterCoordinate:houseCoor animated:YES]}; self.isFirst = NO; [self.mapView addAnnotation:item];}else if (errorCode = = BMK_SEARCH_AMBIGUOUS_KEYWORD) {NSLog (@ "search word ambiguity");} {}else}

The main code here is over. At the end of the article I will attach the Demo
two: path planning
click search, pass a route, and start with the destination. I wanted to directly write the need to pay attention to, but many have been found in the code comments, please pay attention to, such as the time required to / / is a new object, or Pt and name
have the following code deal with a lot of confusion in logic, for one, I did not delete.

#pragma mark - RoutePlanViewDelegate / / search route - (void) didSelectorItems: (NSInteger) item withStartName: (NSString * startName) andEndName: (NSString * endName) {CLLocationCoordinate2D houseCoor; houseCoor.latitude = self.latitude; houseCoor.longitude = self.longitude; / / each time must be a new object, or Pt and name self.startNode [[BMKPlanNode alloc] init] = chaos; self.endNode = [[BMKPlanNode alloc] init]; self.startNode.cityName = @ self.endNode.cityName @ = "Nanjing"; "Nanjing"; / / set the starting point and end point if ([startName "isEqualToString:@" [endName "isEqualToString:@" ||]]) {NSLog (@ "search field ambiguity"); return;} if ([startName isEqualToString:@ &am] "current position" P; & [endName isEqualToString:@ "listings") {self.startNode.pt = self.userLocation.location.coordinate; self.endNode.pt = houseCoor;}else (if [endName isEqualToString:@ &] "current position"; & [startName isEqualToString: @ "listings") {self.startNode.pt = houseCoor; self.endNode.pt = self.userLocation.location.coordinate;}else if ([startName! IsEqualToString:@ "current position". & & [endName isEqualToString:@ "listings") {self.startNode.name = startName; self.endNode.pt = houseCoor;}else if ([startName isEqualToString:@ "current position" & & [endName isEqualToString:@! "Listings") {self.startNode.pt = self.userLocation.location.coordinate; Self.endNode.name = endName;}else if ([startName! IsEqualToString:@ "current position" & & [endName isEqualToString:@ "current position") {self.startNode.name = startName; self.endNode.pt = self.userLocation.location.coordinate;} else (if [startName isEqualToString:@ & & listings "];; [endName! IsEqualToString:@" current position ") {self.startNode.pt = houseCoor; self.endNode.name = endName;}else {self.startNode.name = startName; self.endNode.name = endName;} NSLog (@"% @ - self.startNode.name% @ ", self.endNode.name); if (item = = 1) {/ / BMKDrivingRoutePlanOption *driveRouteSearchOption =[[BMKDrivingRoutePlanOption alloc]init] drive; DriveRouteSearchOption.from = self.startNode; driveRouteSearchOption.to = self.endNode; BOOL = flag [self.routeSearch drivingSearch:driveRouteSearchOption]; if (flag) {}else {}else} if (item = = 2) {/ / option = [[BMKMassTransitRoutePlanOption * BMKMassTransitRoutePlanOption bus alloc]init]; option.from = self.startNode; option.to = self.endNode; BOOL = flag [self.routeSearch massTransitSearch:option]; if (flag) {NSLog (@ "bus traffic the retrieval (support down city)");} else successfully sent {NSLog (@ "bus traffic retrieval (support down city) failed to send");}} else {if (item = = 3) / / walk BMKWalkingRoutePlanOption *walkingRouteSearchOption = [[BMKWalkingRoutePlanOption alloc] init]; walkingRouteSearchOption.from = self.startNode; walkingRouteSearchOption.to = self.endNode; BOOL = flag [self.routeSearch walkingSearch: walkingRouteSearchOption]; if (flag) {NSLog (@ walk retrieve sent successfully;}else) {NSLog (@ walk search failed to send ");}}else {*option = [[BMKRidingRoutePlanOption / BMKRidingRoutePlanOption cycling option.from = alloc]init]; self.startNode; option.to = self.endNode; BOOL = flag [self.routeSearch ridingSearch:option]; if (flag) {NSLog (@" ride planning successfully sent search "); }else {NSLog (@ ride planning to send a search failed);}}}

Click to enter the following agent

#pragma mark - BMKRouteSearchDelegate - (void) onGetDrivingRouteResult: / drive (BMKRouteSearch * searcher) result: (BMKDrivingRouteResult *) result errorCode: (BMKSearchErrorCode) error *array arrayWithArray: self.mapView.annotations] {NSMutableArray = [NSMutableArray; [array removeObjectAtIndex:0]; [self.mapView removeAnnotations:array]; array = [[NSArray arrayWithArray:self.mapView.overlays] mutableCopy]; [self.mapView removeOverlays:array]; if (error = = BMK_SEARCH_NO_ERROR) {/ / represents a driving route BMKDrivingRouteLine *plan = (BMKDrivingRouteLine *) [result.routes objectAtIndex:0]; / / the number of road route calculation int size (int) = [plan.steps count]; int planPointCou Nts for (int = 0; I = 0; I < size; i++) {/ / said driving route in a section of BMKDrivingStep *transitStep = [plan.steps objectAtIndex:i]; if (i==0) {RouteAnnotation *item [[RouteAnnotation = alloc]init]; item.coordinate = plan.starting.location; item.title = @ "starting point"; item.type = 0; [self.mapView / addAnnotation:item]; add the starting point}else (i==size-1) if labeled *item alloc]init] {RouteAnnotation = [[RouteAnnotation; item.coordinate = plan.terminal.location; item.title = @ "end point"; item.type = 1; [self.mapView addAnnotation: Item]; / / add / / add annotation} end point mark node RouteAnnotation *item [[RouteAnnotation = alloc]init]; item.coordinate = transitStep.entrace.location; item.title = transitStep.entraceInstruction; item.degree = transitStep.direction *30; [self.mapView addAnnotation:item]; item.type = 4; / / track point cumulative total planPointCounts + = transitStep.pointsCount;} / / add via if (plan.wayPoints) {for (BMKPlanNode *tempNode in plan.wayPoints) {RouteAnnotation *item = "RouteAnnotation alloc]init]; item.coordinate = tempNode.pt; ite M.type = 5; item.title = tempNode.name; [self.mapView addAnnotation:item];}} / / BMKMapPoint *temppoints = new BMKMapPoint[planPointCounts] locus; int i = 0; for (int j = 0; J < size; j++) {BMKDrivingStep *transitStep = [plan.steps objectAtIndex:j] int; k=0; for (k=0; k< transitStep.pointsCount; k++) {temppoints[i].x = transitStep.points[k].x; temppoints[i].y = transitStep.points[k].y; i++;}} / / *polyLine = [BMKPolyline BMKPolyline building BMKPolyline polylineWithPoints:temppoints count:planPointCounts] by points [self.; MapView addOverlay:polyLine] overlay delete []temppoints; / / add route; [self mapViewFitPolyLine:polyLine];}}

I just put a driving agent, as well as walking, etc. did not put up, too long, the end of the text in order to do not want to download the code to watch the students, I will put the whole page code to provide reference.
well, you found out that I have a custom RouteAnnotation class. This route requires a lot of fields, I do not want to change the pin before the class, and directly rewrite a. as follows

* / * * Custom route marked a pin to convenient, just put it here * / @interface RouteAnnotation: BMKPointAnnotation {int _type; ///< 0:; starting point 1: end point 2: bus 3: 4: 5: int via subway ride _degree; / / rotation angle} @ property (nonatomic) int (nonatomic type; @property int degree; @end) @implementation RouteAnnotation @synthesize type @synthesize = _type; degree = _degree; @end

If you do the same, then do the same as I do in the pin reuse method, and implement this method as follows:

If ([annotation isKindOfClass:[RouteAnnotation class]]) {return [self getRouteAnnotationView:view viewForAnnotation: (RouteAnnotation *) annotation] #pragma mark;} annotation - access to the route, to display map (a custom pin class instance method) I just posted to case 0; the other at the end of search, need to pay attention to where I have written notes - (BMKAnnotationView * (BMKMapView * MapView) getRouteAnnotationView:) viewForAnnotation: (RouteAnnotation * routeAnnotation) {BMKAnnotationView *view = nil; / / pin type according to the judgment is what icon switch (routeAnnotation.type) {case {0: view = [mapview dequeueReusableAnnotationViewWithIdentifier:@ / / to the point of "start_node"]; if (view = = nil View = [[BMKAnnotationView alloc]) {initWithAnnotation:routeAnnotation reuseIdentifier:@ "start_node"]; / / from Baidu map resource files need to get the picture view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@ "images/" icon_nav_start "; view.centerOffset = CGPointMake (0 - (view.frame.size.height * 0.5)); view.canShowCallout = true; view.annotation = routeAnnotation}};

At the end of the line, we added a line, the following code

Through the construction of BMKPolyline BMKPolyline points / / *polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts]; [self.mapView addOverlay:polyLine]; overlay delete []temppoints / / add route; [self mapViewFitPolyLine:polyLine];

In this way, we need to implement a crossed agent. There is a map of the route of the scope of the calculation, the end of the code in the last paragraph, all of which are from the official Baidu map code.

#pragma mark - line line drawing agent (BMKOverlayView *) mapView: (* BMKMapView) map viewForOverlay: (id< BMKOverlay> overlay) {if ([overlay isKindOfClass:[BMKPolyline class]]) {BMKPolylineView *polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay]; / / set the line color polylineView.fillColor = [[UIColor alloc] initWithRed:0 green:1 blue:1 alpha:1]; polylineView.strokeColor alloc] initWithRed:0 = [[UIColor green:0 blue:0.8 alpha:0.7]; polylineView.lineWidth return = 3; polylineView return nil;}};

Although most of the above are copied and pasted, but the Demo code is my intention to prepare, here is mainly to say a process.
Demo portal
packaged, relatively large, I am too lazy to put git, do not want to download the following code
iOS technical exchange group: 511860085 welcome to join!
ViewController all code

HouseMapTootsViewController.m / / / / / / / / Created / / 10 million by Zhang Yulu on 2017/3/6. Copyright Room1000. All rights of 2017 / / reserved. / / #import HouseMapTootsViewController.h #import < BaiduMapAPI_Map/BMKMapComponent.h> #import; < BaiduMapAPI_Location/BMKLocationComponent.h> #import < BaiduMapAPI_Search/BMKSearchComponent.h> #import "YLAnnotationView.h" #import "YLSelectorItemView.h" #import "RoutePlanView.h" #import "SetConstant.h" #import < MapKit/MapKit.h> #import; < MapKit/MapKit.h> #import; UIImage-Extensions.h @interface HouseMapTootsViewController (<); BMKMapViewDelegate, BMKLocationServiceDelegate, BMKPoiSearchDelegate, YLSelectorItemViewDelegate, RoutePlanViewDelegate, BMKRouteSearchDelegate > @property (nonatomic, strong) BMKMapView *mapView; / / Baidu map @property (nonatomic, strong) BMKLocationService *locService; / / @property location services (nonatomic, strong) BMKPoiSearch *poiSearch; / / @property (nonatomic, strong search around BMKNearbySearchOption *option); / / @property (nonatomic, strong) search YLAnnotationView *pointAnnotation; @property (nonatomic, strong) RoutePlanView *planView; / / view @property route planning (nonatomic, strong) BMKRouteSearch *routeSearch; / / @property route search (nonatomic, strong) BMKPlanNode *startNode; / / to the position of @property (nonatomic, strong) BMKPlanNode *endNode @property; / / end position (nonatomic, strong) BMKUserLocation *userLocation; / / @property (nonatomic, assign user location) NSInteger seletItem; / / Note Click on that? @property (nonatomic, assign) BOOL isFirst for the first time in the judgment; / / @end / / location take Baidu Map Resources pictures #define @ MYBUNDLE_NAME "mapapi.bundle" #define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME] #define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH] / * * * mark the custom route a pin to convenient, just put it here: RouteAnnotation / @interface BMKPointAnnotation {int _type; ///< 0:; starting point 1: end point 2: bus 3: 4: 5: int via subway ride _degree; / / rotation angle} @property (nonatomic) int type @property (nonatomic); int degree; @end @implementation RouteAnnotation @synthesize type @synthesize = _type; degree = _deg REE; @end @implementation HouseMapTootsViewController (BMKNearbySearchOption * Option) {if (_option! = [[BMKNearbySearchOption) {_option alloc] init]}; return _option;} - (RoutePlanView * planView) {if (! _planView) {_planView = [[RoutePlanView alloc] initWithFrame:CGRectMake (0, 64, kScreenWidth, 245); _planView.delegate = self;} return _planView;} - (BMKPoiSearch * poiSearch) {if (_poiSearch! = [[BMKPoiSearch) {_poiSearch alloc] init]}; return _poiSearch;} - (BMKRouteSearch * routeSearch) {if (! _routeSearch) {_routeSearch alloc]init] = [[BMKRouteSearch; _routeSearch.delegate = self;} return _routeSearch;} - (NSString * getMyB) UndlePath1: (NSString * filename) {NSBundle *libBundle = MYBUNDLE (libBundle & if; & filename) {NSString *s = [[libBundle resourcePath] stringByAppendingPathComponent:filename]; return s;} return nil;} #pragma mark - life cycle - (void) viewDidLoad {[super viewDidLoad]; self.title = @ "POI search and route planning"; self.view.backgroundColor = [UIColor whiteColor]; [self setupUI];} - (void) viewWillAppear: (BOOL) animated {[self.mapView viewWillAppear]; self.mapView.delegate = self; / / here remember when not set to nil, or affect the memory of the release of self.routeSearch.delegate = self; / / when not in use, nil self.poiSearch.delegate = self; self.locService.dele Gate = self;} - (void) viewWillDisappear: (BOOL) animated {[self.mapView viewWillDisappear]; self.mapView.delegate = nil; / / when not in use, nil self.routeSearch.delegate = nil; / / when not in use, nil self.poiSearch.delegate = nil; self.locService.delegate = nil; self.option = nil; [self.locService stopUserLocationService]; / / for adding a lot of agents, there must be clear all otherwise, the memory is not released for (BMKPoiSearch *poi in self.poiDetails) {poi.delegate = nil;} [self.poiDetails removeAllObjects]; / / if there is a sub page in the appear rejoined [self.mapView removeFromSuperview];} - (void) dealloc (self.mapView) {if {self.mapView} if (s = nil; Elf.routeSearch) {self.routeSearch.delegate = nil; / / when not in use, nil (self.poiSearch)} if {self.poiSearch.delegate = nil;} if (self.locService) {self.locService.delegate}} = nil; #pragma mark - set UI interface - (void) setupUI *itemView alloc] initWithFrame:CGRectMake {YLSelectorItemView = [[YLSelectorItemView (0, 64, kScreenWidth, 40) andTitles:@[@ delicacy, "supermarket", "@ @ @" ATM "," shopping ""; itemView.delegate = self; [self.view addSubview: itemView]; self.mapView [[BMKMapView alloc] = initWithFrame:CGRectMake (0, 40+64, kScreenWidth, kScreenHeight - 40 - 64)]; [self.view addSubview:self.mapView]; [self.view addSubview:self.planView]; self.locService = [[BMKLo CationService alloc] init]; self.mapView.delegate = self; self.locService.delegate = self; / / orientation mode cannot be used to follow, otherwise it is not the center of the map pins [self.mapView setZoomLevel:16]; self.mapView.showMapScaleBar = YES; self.mapView.userTrackingMode = BMKUserTrackingModeNone; self.mapView.showsUserLocation = YES; [self.locService startUserLocationService]; CLLocationCoordinate2D coor; coor.latitude = self.latitude; coor.longitude = self.longitude; if (self.pointAnnotation = = Nil) {/ / custom pin self.pointAnnotation = [[YLAnnotationView alloc]init]; self.pointAnnotation.coordinate = coor; self.pointAnnotation.title = @ "houses a The "; self.pointAnnotation.subtitle = @" click here "; self.pointAnnotation.image imageNamed:@ [UIImage =" homelocation "]}; [self.mapView addAnnotation:self.pointAnnotation]; / / set the center point [self.mapView setCenterCoordinate:coor]; / / self.poiSearch.delegate = self retrieval facilities; / / add pins added after peripheral search self.option.location = coor; self.option.pageIndex = 0; self.option.pageCapacity = 20; self.option.radius = 1500; self.option.keyword = @" delicacy "; self.isFirst = YES; BOOL = flag [self.poiSearch poiSearchNearBy:self.option]; if (flag) {NSLog (@" around search successfully sent ");}else {NSLog (@" around search failed to send "); Self.seletItem = 1};} / / apple native libraries calculate two latitude direct distance (double) distanceBetweenOrderByLatitude1: (double) latitude1 Longitude1: (double) longitude1 andLatitude2: (double) latitude2 Longitude2: (double) longitude2 CLLocation [[CLLocation alloc] initWithLatitude:latitude1 {*curLocation = longitude:longitude1]; CLLocation = *otherLocation [[CLLocation alloc] initWithLatitude:latitude2 longitude:longitude2]; double distance = [curLocation distanceFromLocation: otherLocation]; return distance;} #pragma mark - YLSelectorItemViewDelegate - (void) didSelectedItems: (NSInteger) item {CLLocationCoordinate2D coor; coor.latitude = self.latitude; coor.longitude = self.longitude; self.se LetItem = item; self.isFirst = YES; if (item = = 1) {self.option.keyword = @ "delicacy"; BOOL flag = [self.poiSearch poiSearchNearBy:self.option]; if (flag) {NSLog (@ "around search successfully sent");}else {NSLog (@ "around search failed to send");}else if (item = = 2}) {self.option.keyword = @ "supermarket"; BOOL flag1 = [self.poiSearch poiSearchNearBy:self.option]; if (flag1) {NSLog (@ "around search successfully sent");}else {}else} if (item = = 3) {self.option.keyword = @ "ATM"; BOOL Flag2 = [self.poiSearch poiSearchNearBy:self.option]; if (Flag2) {NSLog (@ "send around search success");} Else {NSLog (@ "around search failed to send");}}else if (item = = 4) {self.option.keyword = @ "shopping"; BOOL flag3 = [self.poiSearch poiSearchNearBy:self.option]; if (flag3) {NSLog (@ "around search successfully sent");}else {NSLog (@ "around search failed to send"); #pragma mark implement BMKMapViewDelegate}}} / * * * * / View according to the annotation of anntation to generate the corresponding View *@param view View *@param annotation the specified annotation map generated by *@return - (BMKAnnotationView *) mapView: (BMKMapView *) view viewForAnnotation: (ID < BMKAnnotation> annotation) {if ([annotation isKindOfClass:[RouteAnnotation class]]) {return [self getRouteAnnotationView:vie W viewForAnnotation: (RouteAnnotation * annotation]);} / / *AnnotationViewID = NSString identifier generation reuse marked @ "DaTouZhen"; / / check reuse of cached BMKAnnotationView *annotationView = [view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; / / cache miss, have constructed a general, first add annotation code will run to the if (annotationView = = Nil) {annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; ((BMKPinAnnotationView*) annotationView).AnimatesDrop = NO;} / / custom pin YLAnnotationView *yl_A = (YLAnnotationView * annotation); annotationView.annotation = yl_A; ANN OtationView.image = yl_A.image; annotationView.centerOffset = CGPointMake / / location (0 - (annotationView.frame.size.height, *0.5)); annotationView.annotation = annotation; / / click pop-up pop-up bubbles, bubble annotation premise must implement the title attribute annotationView.canShowCallout = YES; / / set whether you can drag the annotationView.draggable = NO; return annotationView;} / / click popView call - (void) mapView: (BMKMapView * mapView annotationViewForBubble: (BMKAnnotati)