# import < BaiduMapAPI_Base / BMKBaseComponent . h > # import < BaiduMapAPI_Map / BMKMapComponent . h > //The mapView of the current interface @ property ( nonatomic , strong ) BMKMapView * mapView ; - ( void ) viewDidLoad { [ super viewDidLoad ] ; _mapView = [ [ BMKMapView alloc ] initWithFrame : self . view . bounds ] ; //Set the proxy of mapView _mapView . delegate = self ; //Add mapView to the current view [ self . view addSubview : _mapView ] ; } - ( void ) viewWillAppear : ( BOOL ) animated { [ super viewWillAppear : animated ] ; //Called when the mapView is about to be displayed to restore the previously stored mapView state [ _mapView viewWillAppear ] ; } - ( void ) viewWillDisappear : ( BOOL ) animated { [ super viewWillDisappear : animated ] ; //Called when the mapView is about to be hidden to store the status of the current mapView [ _mapView viewWillDisappear ] ; }
# import < BaiduMapAPI_Base / BMKBaseComponent . h > # import < BaiduMapAPI_Map / BMKMapComponent . h > BMKMapView * mapView = [ [ BMKMapView alloc ] initWithFrame : self . view . bounds ] ; //Set the proxy of mapView mapView . delegate = self ; //Add mapView to the current view [ self . view addSubview : mapView ] ; //Set the center point of the current map. When changing this value, the scale level of the map will not change mapView . centerCoordinate = CLLocationCoordinate2DMake ( thirty-nine point nine one seven , one hundred and sixteen point three seven nine ) ; //Set Map Scale Level mapView . zoomLevel = eighteen ; mapView . baseIndoorMapEnabled = YES ; mapView . showIndoorMapPoi = YES ; #pragma mark - BMKMapViewDelegate /** *This interface will be called when the map enters/moves out of the interior map *@Param mapView *@Param flag YES: enter the interior map; NO: Move out of interior drawing *@Param info */ - ( void ) mapview : ( BMKMapView * ) mapView baseIndoorMapWithIn : ( BOOL ) flag baseIndoorMapInfo : ( BMKBaseIndoorMapInfo * ) info { if ( flag ) { //Enter the interior drawing } else { //Move out of interior drawing } }
# import < BaiduMapAPI_Base / BMKBaseComponent . h > # import < BaiduMapAPI_Map / BMKMapComponent . h > BMKMapView * mapView = [ [ BMKMapView alloc ] initWithFrame : self . view . bounds ] ; //Set the proxy of mapView mapView . delegate = self ; //Add mapView to the current view [ self . view addSubview : mapView ] ; BMKMapStatus * status = [ [ BMKMapStatus alloc ] init ] ; status . fLevel = ten ; status . targetGeoPt = CLLocationCoordinate2DMake ( fifty-one point five zero five five six , - zero point zero seven five five six ) ; [ mapView setMapStatus : status withAnimation : YES withAnimationTime : one thousand ] ;
# import < BaiduMapAPI_Base / BMKBaseComponent . h > # import < BaiduMapAPI_Map / BMKMapComponent . h > - ( void ) viewDidLoad { [ super viewDidLoad ] ; BMKMapView * mapView = [ [ BMKMapView alloc ] initWithFrame : self . view . bounds ] ; //Set the proxy of mapView mapView . delegate = self ; //Add mapView to the current view [ self . view addSubview : mapView ] ; //Initialize the instance of dimension class BMKPointAnnotation BMKPointAnnotation * annotation = [ [ BMKPointAnnotation alloc ] init ] ; //Set the latitude and longitude coordinates of the dimension annotation . coordinate = CLLocationCoordinate2DMake ( thirty-nine point nine one five , one hundred and sixteen point four zero four ) ; //Set the title of the dimension annotation . title = @ Dimension ; //Subtitle annotation . subtitle = @ "Draggable" ; /** To add annotations to the current map, you need to implement the - mapView: viewForAnnotation: method of BMKMapViewDelegate To generate the corresponding view of the dimension @Param annotation */ [ mapView addAnnotation : annotation ] ; } #pragma mark - BMKMapViewDelegate /** Generate corresponding annotationView according to annotation @Param mapView @Dimension specified by param annotation @Return Generated annotation view */ - ( BMKAnnotationView * ) mapView : ( BMKMapView * ) mapView viewForAnnotation : ( id < BMKAnnotation > ) annotation { if ( [ annotation isKindOfClass : [ BMKPointAnnotation class ] ] ) { /** Find a reusable label according to the specified label, use this method to replace the newly created label, and return the reusable label */ BMKPinAnnotationView * annotationView = ( BMKPinAnnotationView * ) [ mapView dequeueReusableAnnotationViewWithIdentifier : @ "annotationViewIdentifier" ] ; if ( ! annotationView ) { /** Initialize and return an annotationView @The annotation object associated with param annotation @Param reuseIdentifier If you want to reuse the view, pass in a string. Otherwise, set it to nil. It is recommended to reuse the view @Return If initialization is successful, annotationView is returned; otherwise, nil is returned */ annotationView = [ [ BMKPinAnnotationView alloc ] initWithAnnotation : annotation reuseIdentifier : @ "annotationViewIdentifier" ] ; //The image displayed by annotationView is a pin by default //annotationView.image = nil; /** By default, the center point of the annotation view is located at the coordinate position of the annotation. You can set centerOffset to change The position of the annotationView. A positive offset moves the annotationView to the bottom right, and a negative offset moves it to the top left, in pixels */ annotationView . centerOffset = CGPointMake ( zero , zero ) ; /** By default, the pop-up bubble is located above the middle of the annotationView. You can set calloutOffset to change the Position: positive offset makes the annotationView move to the lower right, and negative offset moves to the upper left, in pixels */ annotationView . calloutOffset = CGPointMake ( zero , zero ) ; //Whether to display 3D effect, mark whether to follow the rotation and top view during map rotation and top view. The default value is NO annotationView . enabled3D = NO ; //Whether to ignore the touch time, the default is YES annotationView . enabled = YES ; /** Developers should not set this property directly. If it is set, they need to call BMKMapView's - (void) mapForceRefresh after setting; method Refresh the map. The default value is NO. When annotationView is selected, it is YES */ annotationView . selected = NO ; //Whether to display bubbles when annotationView is selected (if it is displayed, annotation must be set with title). The default value is YES annotationView . canShowCallout = YES ; /** The view displayed on the left side of the bubble (when the default bubble is used, the maximum width of the view is 32, The maximum height is 41, and the maximum value is used if it is greater than) */ annotationView . leftCalloutAccessoryView = nil ; /** The view displayed on the right side of the bubble (when the default bubble is used, the maximum width of the view is 32, The maximum height is 41, and the maximum value is used if it is greater than) */ annotationView . rightCalloutAccessoryView = nil ; /** AnnotationView color: BMKPinAnnotationColorRed, BMKPinAnnotationColorGreen, BMKPinAnnotationColorPurple */ annotationView . pinColor = BMKPinAnnotationColorRed ; //Set the animation effect of falling from the sky annotationView . animatesDrop = YES ; //When set to YES and the setCoordinate: method is implemented, annotationView can be dragged on the map annotationView . draggable = YES ; //The dragging status of the current view //annotationView.dragState; } return annotationView ; } return nil ; }
# import < BaiduMapAPI_Base / BMKBaseComponent . h > # import < BaiduMapAPI_Search / BMKSearchComponent . h > BMKSuggestionSearch * suggestionSearch = [ [ BMKSuggestionSearch alloc ] init ] ; suggestionSearch . delegate = self ; BMKSuggestionSearchOption * suggestionOption = [ [ BMKSuggestionSearchOption alloc ] init ] ; suggestionOption . keyword = @ McDonald's ; suggestionOption . cityname = @ Beijing ; suggestionOption . cityLimit = NO ; /** Keyword retrieval, asynchronous method, and the returned results are displayed in BMKSuggestionSearchDelegate OnGetSuggestionResult SuggestionOption sug Retrieve information class YES is returned successfully, otherwise NO is returned */ BOOL flag = [ suggestionSearch suggestionSearch : suggestionOption ] ; if ( flag ) { NSLog ( @ "Keyword search succeeded" ) ; } else { NSLog ( @ "Keyword search failed" ) ; } #pragma mark - BMKSuggestionSearchDelegate /** Keyword search result callback @Param searcher retrieves objects @Param result keyword search result @Param error code, @ see BMKCloudErrorCode */ - ( void ) onGetSuggestionResult : ( BMKSuggestionSearch * ) searcher result : ( BMKSuggestionSearchResult * ) result errorCode : ( BMKSearchErrorCode ) error { //BMKSearchErrorCode error code, BMK_SEARCH_NO_ERROR: the search result is returned normally if ( error == BMK_SEARCH_NO_ERROR ) { //Realize the processing of search results } } //Initialize BMKPoiSearch instance BMKPoiSearch * poiSearch = [ [ BMKPoiSearch alloc ] init ] ; //Set proxy for POI retrieval poiSearch . delegate = self ; //Initialize the instance of request parameter class BMKNearbySearchOption BMKPOINearbySearchOption * nearbyOption = [ [ BMKPOINearbySearchOption alloc ] init ] ; /** Search keyword, required. In peripheral retrieval, the keywords are array types, which can support multiple keyword union retrieval, such as bank and hotel. Each keyword corresponds to an element of the array. Up to 10 keywords are supported. */ nearbyOption . keywords = @ [ @ McDonald's ] ; //Retrieve the longitude and latitude of the center point, required nearbyOption . location = CLLocationCoordinate2DMake ( forty point zero five six nine seven four , one hundred and sixteen point three zero seven six eight nine ) ; /** Retrieves the radius in meters. When the radius is too large and exceeds the city boundary of the center point, it will become a city wide search, and the search range is the city of the center point */ nearbyOption . radius = one thousand ; /** Initiate peripheral retrieval according to the center point, radius and search term: asynchronous method, and the returned results are displayed in BMKPoiSearchDelegate OnGetPoiResult Search parameter class of nearbyOption peripheral search YES is returned successfully, otherwise NO is returned */ BOOL flag = [ poiSearch poiSearchNearBy : nearbyOption ] ; if ( flag ) { NSLog ( @ "POI perimeter retrieval succeeded" ) ; } else { NSLog ( @ "Failed to retrieve POI perimeter" ) ; } #pragma mark - BMKPoiSearchDelegate /** POI retrieval return result callback @Param searcher retrieves objects @Param poiResult POI search result list @Param error error code */ - ( void ) onGetPoiResult : ( BMKPoiSearch * ) searcher result : ( BMKPOISearchResult * ) poiResult errorCode : ( BMKSearchErrorCode ) error { //BMKSearchErrorCode error code, BMK_SEARCH_NO_ERROR: the search result is returned normally if ( error == BMK_SEARCH_NO_ERROR ) { //Realize the processing of search results } }
# import < BaiduMapAPI_Base / BMKBaseComponent . h > # import < BaiduMapAPI_Search / BMKSearchComponent . h > //Initialize BMKRouteSearch instance BMKRouteSearch * drivingRouteSearch = [ [ BMKRouteSearch alloc ] init ] ; //Planning for setting driving routes drivingRouteSearch . delegate = self ; BMKDrivingRoutePlanOption * drivingRoutePlanOption = [ [ BMKDrivingRoutePlanOption alloc ] init ] ; //Instantiate line retrieval node information class object BMKPlanNode * start = [ [ BMKPlanNode alloc ] init ] ; //Start name start . name = @ Tiananmen ; //City of origin start . cityName = @ Beijing ; //Instantiate line retrieval node information class object BMKPlanNode * end = [ [ BMKPlanNode alloc ] init ] ; //End Name end . name = @ "Baidu Science Park" ; //Destination city end . cityName = @ Beijing ; //The starting point of retrieval can be specified by keyword and coordinate. When cityName and cityID are specified at the same time, cityID is preferred drivingRoutePlanOption . from = start ; //The end point of retrieval can be specified by keyword and coordinate. When cityName and cityID are specified at the same time, cityID is preferred drivingRoutePlanOption . to = end ; NSMutableArray * wayPointsArray = [ [ NSMutableArray alloc ] initWithCapacity : one ] ; BMKPlanNode * wayPointItem = [ [ BMKPlanNode alloc ] init ] ; wayPointItem . cityName = @ Beijing ; wayPointItem . name = @ "Xierqi Metro Station" ; [ wayPointsArray addObject : wayPointItem ] ; drivingRoutePlanOption . wayPointsArray = wayPointsArray ; /** Initiate a drive route retrieval request, an asynchronous function, and the returned result is in onGetDriveingRouteResult of BMKRouteSearchDelegate */ BOOL flag = [ drivingRouteSearch drivingSearch : drivingRoutePlanOption ] ; if ( flag ) { NSLog ( @ "Successful car search" ) ; } else { NSLog ( @ "Car search failed" ) ; } #pragma mark - BMKRouteSearchDelegate /** *Return to driving search results *@Param searcher search object *@Param result search result, the type is BMKDrivingRouteResult *@Param error error number, @ see BMKSearchErrorCode */ - ( void ) onGetDrivingRouteResult : ( BMKRouteSearch * ) searcher result : ( BMKDrivingRouteResult * ) result errorCode : ( BMKSearchErrorCode ) error { //BMKSearchErrorCode error code, BMK_SEARCH_NO_ERROR: the search result is returned normally if ( error == BMK_SEARCH_NO_ERROR ) { //Realize the processing of search results } }
# import < BaiduMapAPI_Map_For_WalkNavi / BMKMapComponent . h > # import < BaiduMapAPI_WalkNavi / BMKWalkNaviComponent . h > @ property ( nonatomic , strong ) BMKWalkNaviViewController * controller ; ///Navigation page _controller = [ [ BMKWalkNaviViewController alloc ] init ] ; BOOL inited = [ [ BMKWalkNavigationManager sharedManager ] initNaviEngine : _controller ] ; [ BMKWalkNavigationManager sharedManager ] . routePlanDelegate = self ; [ BMKWalkNavigationManager sharedManager ] . routeGuidanceDelegate = self ; [ BMKWalkNavigationManager sharedManager ] . ttsPlayerDelegate = self ; if ( inited ) { NSLog ( @ "SDK - Engine initialization succeeded" ) ; BMKWalkNaviLaunchParam * param = [ [ BMKWalkNaviLaunchParam alloc ] init ] ; param . startPoint = CLLocationCoordinate2DMake ( forty point zero four nine eight seven nine , one hundred and sixteen point two seven nine eight five three ) ; //Starting point coordinate, Baidu Science Park; param . endPoint = CLLocationCoordinate2DMake ( forty point zero five eight nine one eight , one hundred and sixteen point three one two six two one ) ; //Terminal coordinates, Xierqi Metro Station; [ [ BMKWalkNavigationManager sharedManager ] routePlanWithParams : param ] ; } #pragma mark - BMKWalkCycleRoutePlanDelegate /** Start counting */ - ( void ) onRoutePlanStart : ( BMKWalkCycleNavigationType ) naviType { NSLog ( @ "SDK - Start Routing" ) ; } - ( void ) onRoutePlanResult : ( BMKWalkCycleRoutePlanErrorCode ) errorCode naviType : ( BMKWalkCycleNavigationType ) naviType { if ( errorCode == BMK_WALK_CYCLE_ROUTEPLAN_RESULT_SUCCESS ) { NSLog ( @ "SDK - route calculation successful" ) ; _controller . navigationType = zero ; [ self . navigationController pushViewController : _controller animated : YES ] ; } else { NSLog ( @ "SDK - route calculation failed" ) ; } } //BMKWalkNaviViewController - ( void ) viewWillAppear : ( BOOL ) animated { [ super viewWillAppear : animated ] ; self . navigationController . navigationBarHidden = YES ; [ [ BMKWalkNavigationManager sharedManager ] resume ] ; [ [ BMKWalkNavigationManager sharedManager ] startWalkNavi : BMK_WALK_NAVIGATION_MODE_WALK_NORMAL ] ; //BMK_WALK_NAVIGATION_MODE_WALK_AR } - ( void ) viewWillDisappear : ( BOOL ) animated { [ super viewWillDisappear : animated ] ; self . navigationController . navigationBarHidden = NO ; [ BMKWalkNavigationManager destroy ] ; }
//BMKWalkRoutePlanController # import < BaiduMapAPI_Map_For_WalkNavi / BMKMapComponent . h > # import < BaiduMapAPI_WalkNavi / BMKWalkNaviComponent . h > @ property ( nonatomic , strong ) BMKWalkNaviViewController * controller ; ///Navigation page BMKWalkCycleNavigationDisplayOption * naviOption = [ [ BMKWalkCycleNavigationDisplayOption alloc ] init ] ; _controller = [ [ BMKWalkNaviViewController alloc ] init ] ; BOOL inited = [ [ BMKCycleNavigationManager sharedManager ] initNaviEngine : _controller option : naviOption ] ; [ BMKCycleNavigationManager sharedManager ] . routePlanDelegate = self ; [ BMKCycleNavigationManager sharedManager ] . routeGuidanceDelegate = self ; [ BMKCycleNavigationManager sharedManager ] . ttsPlayerDelegate = self ; if ( inited ) { NSLog ( @ "SDK - Engine initialization succeeded" ) ; BMKCycleNaviLaunchParam * param = [ [ BMKCycleNaviLaunchParam alloc ] init ] ; param . startPoint = CLLocationCoordinate2DMake ( forty point zero four nine eight seven nine , one hundred and sixteen point two seven nine eight five three ) ; //Starting point coordinate, Baidu Science Park; param . endPoint = CLLocationCoordinate2DMake ( forty point zero five eight nine one eight , one hundred and sixteen point three one two six two one ) ; //Terminal coordinates, Xierqi Metro Station; param . naviType = BMK_WALK_CYCLE_NAVIGATION_TYPE_ELECTRIC_CYCLE ; [ [ BMKCycleNavigationManager sharedManager ] routePlanWithParams : param ] ; } #pragma mark - BMKWalkCycleRoutePlanDelegate /** Start counting */ - ( void ) onRoutePlanStart : ( BMKWalkCycleNavigationType ) naviType { NSLog ( @ "SDK - Start Routing" ) ; } - ( void ) onRoutePlanResult : ( BMKWalkCycleRoutePlanErrorCode ) errorCode naviType : ( BMKWalkCycleNavigationType ) naviType { if ( errorCode == BMK_WALK_CYCLE_ROUTEPLAN_RESULT_SUCCESS ) { NSLog ( @ "SDK - route calculation successful" ) ; _controller . navigationType = one ; [ self . navigationController pushViewController : _controller animated : YES ] ; } else { NSLog ( @ "SDK - route calculation failed" ) ; } } //BMKWalkNaviViewController - ( void ) viewWillAppear : ( BOOL ) animated { [ super viewWillAppear : animated ] ; self . navigationController . navigationBarHidden = YES ; [ [ BMKCycleNavigationManager sharedManager ] resume ] ; [ [ BMKCycleNavigationManager sharedManager ] startCycleNavi ] ; } - ( void ) viewWillDisappear : ( BOOL ) animated { [ super viewWillDisappear : animated ] ; self . navigationController . navigationBarHidden = NO ; [ BMKCycleNavigationManager destroy ] ; }