All service products
Developer Channel
Service upgrade
Sign in

All documents

IOS Map SDK

summary

developer's guide

IOS Map SDK
Baidu Maps iOS SDK is an application program interface based on iOS 10.0 and above devices. You can use this SDK to develop map applications for iOS mobile devices. By calling the map SDK interface, you can easily access Baidu map services and data, and build map applications with rich functions and strong interactivity.

Important: In order to further take measures to strengthen the security protection of the end user's personal information, from the Map SDK v6.5.1 version, the developer must ensure that the privacy compliance interface setAgreePrivacy is called before calling any interface of the SDK, or the related functions may not be used normally. For details, please refer to Development Guide - Development Considerations - Privacy Policy Interface Description.

Product Introduction
The iOS Map SDK can be used for iOS native development, supporting map display (indoor map, outdoor map), map interaction, drawing on maps, retrieving map data and other functions. The map SDK provides a wealth of point, line, surface and model drawing capabilities to meet the personalized needs of various business scenarios.
Introduction to key functions
Map display and interaction
brief introduction
Map display: general map (2D, 3D), satellite map and real-time traffic map. Open HD 4K map display.
Map interaction: click, double click, long press, zoom, rotate, change perspective and other operations of the map can be realized through interface or gesture control.
Function display
# 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 ] ;
}
Interior drawing
brief introduction
Since Baidu Map SDK V3.0, the indoor map function has been officially launched, assisting developers to achieve a new geographical location service experience, and the indoor map and Baidu Map App are updated synchronously;
The public buildings supported include shopping malls, airports, railway stations and other transportation hubs, hospitals, etc., covering more than 4000 large-scale shopping centers nationwide.
Function display
# 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
}
}
Overseas map
brief introduction
Baidu Maps SDK supports the display capability of overseas maps, including detailed road, POI and other data display in more than 200 countries and regions around the world.
Function display
# 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 ] ;
Map cover
brief introduction
Baidu Maps SDK supports a variety of map covers to help you display more abundant maps. Map coverage: map marking, geometry (points, polylines, arcs, polygons, etc.), coverage of POI retrieval results, coverage of route planning results, etc;
Function display
# 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 ;
}
POI retrieval
brief introduction
Baidu Map SDK supports peripheral search, regional search, urban search and POI details search.
Peripheral search: take a point as the center, specify a distance as the radius, and perform POI search according to the keywords entered by the user;
Area retrieval: POI retrieval is performed according to keywords within the specified rectangular area;
In city search: in a city, POI search is carried out according to the keywords entered by the user;
POI details retrieval: retrieve the details of the point of interest according to the ID information of the POI.
Function display
# 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
}
}
Route planning
brief introduction
Baidu Maps SDK supports bus, driving, cycling, walking and cross city public transport route planning.
Bus route planning: according to the starting and ending points, carry out bus route planning;
Driving route planning: according to the starting and ending points and different strategies, the driving route planning is carried out, and the setting of passing points is supported;
Cycling route planning: according to the starting and ending points, the planning of cycling routes is carried out, and cross city cycling route planning is supported;
Pedestrian route planning: pedestrian route planning shall be carried out according to the starting and ending points;
Cross city public transport route planning: carry out cross city route planning according to the starting and ending points, and support multiple travel plans such as planes, trains, buses, and buses.
Function display
# 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
}
}
Pedestrian navigation
brief introduction
In V4.2.0, the pedestrian navigation function is added, which supports ordinary pedestrian navigation, pedestrian AR navigation, yaw correction and other navigation functions.
Function display
# 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 ] ;
}
Cycling navigation
brief introduction
In V4.2.0, a new riding navigation function is added, which supports navigation functions such as ordinary bicycle riding navigation, electric bicycle riding navigation, yaw correction, etc.
Function display
//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 ] ;
}
Notice to users
Please read and agree before you use Baidu iOS Map SDK Service Terms of Baidu Map Open Platform And Request Key (AK) Can be used.
If you encounter any problems in use, you can go to Feedback platform Give us feedback, and then technical support personnel will deal with the problem one-on-one for you.
Free Instructions
At present, Baidu Maps iOS Map SDK domestic service does not charge any fees for developers who use it for non-commercial purposes, and developers can use it themselves download Use with confidence.
If you use the services of the platform for commercial purposes (including but not limited to charging third-party users, project bidding, and other direct or indirect gains or benefits), users must obtain the platform in advance "Commercial Authorization" permit. The authorized object of platform commercial authorization is the company entity. After the authorization is successful, you will receive the written commercial authorization provided by the platform (with the signature and seal of Baidu).
Commercial authorization can click here Learn more. Please refer to Instructions

Next

Get Key

Is this article helpful to you?