IOS Baidu map SDK usage summary, ios map sdk Summary
Although there are many official integration introductions, I have used a little, except for the import of the basic library and the use of AppDelegate from regist, at least the code for obtaining the current geographic location is considered to be not clear enough.
This section describes how to enable positioning, anti-encoding of geographic coordinates, and city cloud search.
BMKLocationServiceDelegate, BMKGeoCodeSearchDelegate
Proxy Method for homepage Import
Second, enable the Baidu positioning service
[BMKLocationServicesetLocationDesiredAccuracy: kCLLocationAccuracyNearestTenMeters];
[BMKLocationServicesetLocationDistanceFilter: kCLLocationAccuracyBest];
// Initialize BMKLocationService
_ LocService = [[BMKLocationServicealloc] init];
_ LocService. delegate = self;
// Start LocationService
[_ LocServicestartUserLocationService];
The proxy method is called to obtain the current latitude and longitude, and then use the search coordinates.
-(Void) didUpdateBMKUserLocation :( BMKUserLocation *) userLocation
{
NSLog (@ "didUpdateUserLocation lat % f, long % f", userLocation. location. coordinate. latitude, userLocation. location. coordinate. longpolling );
// We recommend that you stop position update after obtaining the latitude and longitude information; otherwise, coordinates will be updated all the time.
If (userLocation. location. coordinate. latitude! = 0 ){
[_ LocServicestopUserLocationService];
}
// Call Search
BMKGeoCodeSearch * search = [[BMKGeoCodeSearchalloc] init];
Search. delegate = self;
BMKReverseGeoCodeOption * rever = [[BMKReverseGeoCodeOptionalloc] init];
Rever. reverseGeoPoint = userLocation. location. coordinate;
// Do not delete this code
NSLog (@ "% d", [searchreverseGeoCode: rever]);
}
The specific address can be returned in the search proxy method.
# Pragma mark GeoCodeResult returns the geographical location
-(Void) onGetReverseGeoCodeResult :( BMKGeoCodeSearch *) searcher result :( BMKReverseGeoCodeResult *) result errorCode :( BMKSearchErrorCode) error
{
NSLog (@ "% @", result. address );
}
The above is the code for obtaining the current geographic location.
I am using the system's normal SearchBar in cloud search, and trigger the cloud search import proxy in its proxy method.
BMKGeoCodeSearchDelegate, BMKLocationServiceDelegate, bmkcancearchdelegate
-(Void) searchBar :( UISearchBar *) searchBar textDidChange :( NSString *) searchText
{
// Initialize poi search
_ Receivearch = [[bmkreceivearchalloc] init];
_ Earch. delegate = self;
BMKCitySearchOption * option = [[BMKCitySearchOptionalloc] init];
Option. city = @ "Beijing ";
_ SearchTextFiled. placeholder = @ "Enter the address to switch ";
Option. keyword = _ searchTextFiled. text;
BOOL flag = [_ earchreceivearchincity: option];
If (flag)
{
// NSLog (@ "successful sending of peripheral search ");
}
Else
{
// NSLog (@ "failed to send peripheral search ");
}
}
-(Void) onGetPoiResult :( bmkdomainearch *) searcher
Result :( BMKPoiResult *) poiResultList
ErrorCode :( BMKSearchErrorCode) error
{
If (error = BMK_SEARCH_NO_ERROR ){
// The result poiResultList. totalPoiNum and poiResultList. poiInfoList indicate the number of search results and the number of saved addresses respectively. You can use the forin array to traverse poiResultList. poiInfoList.
NSLog (@ "% d % @", poiResultList. totalPoiNum, poiResultList. poiInfoList );
NSArray * array = poiResultList. poiInfoList;
}
Elseif (error = BMK_SEARCH_AMBIGUOUS_KEYWORD ){
// When no result is found in the specified city but the result is found in another city, callback is recommended to retrieve the city list
// Result. cityList;
NSLog (@ "the starting point is ambiguous ");
} Else {
NSLog (@ "sorry, no result found ");
}
}
The above is the city cloud search code. For other popular searches, you can refer to the class reference search in Baidu map Developer Center.
If you have any questions, please leave a message.