All Products
Search
Document Center

Mobile Platform as a Service:Use Baidu Map in Mini Program

Last Updated:Feb 07, 2025

my.getLocation supports Baidu SDK

  1. Set the switch in the initialize method.

    - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    	[LBSmPaaSAdaptorsharedInstance].shouldSkipLBSLocation = YES;
    }
  2. Implement the AriverMapEngineDelegate and BMKGeoCodeSearchDelegate protocols on the page. Import the header file #import <APMobileLBS/LBSmPaaSAdaptor.h>.

    @interfaceViewController : UIViewController<AriverMapEngineDelegate,BMKGeoCodeSearchDelegate>
    @property (nonatomic, copy) mapReGeocodeCompletedBlockreGeoBlock;
    @end
    - (void)viewDidLoad {
    	[superviewDidLoad];
    	[LBSmPaaSAdaptorsharedInstance].ariverMapEngineDelegate = self;
    }
  3. Implement the methods in the protocol.

    #pragma mark - AriverMapEngineDelegate
    -(void)mPaaSReverseWithLocation:(APMapReGeoRequest*)reGeoRequest completion:(mapReGeocodeCompletedBlock)completion {
    	BMKGeoCodeSearch *search = [[BMKGeoCodeSearchalloc] init];
      search.delegate = self;
      BMKReverseGeoCodeSearchOption *reGeoCodeSearchOption = [[BMKReverseGeoCodeSearchOptionalloc]init];
      reGeoCodeSearchOption.location = reGeoRequest.coordinate;
      self.reGeoBlock = completion;
      BOOL flag = [search reverseGeoCode:(BMKReverseGeoCodeSearchOption *)reGeoCodeSearchOption];
    }
    #pragma mark - BMKGeoCodeSearchDelegate
    /**
    *Return reverse geocoding search results
    *@param searcher Search object
    *@param result Search result
    *@param error Error code, @see BMKSearchErrorCode
    */
    - (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error {
      if (result) {
        NSDictionary* resultDic = [selfparseLBSAddressInfo:result searcher:searcher];
        self.reGeoBlock(resultDic, nil);
      }else{
        NSMutableDictionary *infoDic = [[NSMutableDictionaryalloc] initWithCapacity:1];
        infoDic[NSLocalizedDescriptionKey] = 		__TEXT(@"APMobileLBS",@"APMobileLBS:APMapService.requestFail", @"Request result is empty");
        
        NSError *resultError = [[NSErroralloc] initWithDomain:@"APMapService"code:error userInfo:infoDic];
        self.reGeoBlock(nil, resultError);
      }
    }
     (NSDictionary )parseLBSAddressInfo:(BMKReverseGeoCodeSearchResult )result
    searcher:(BMKGeoCodeSearch *)searcher
    {
      if (!result) {
      	return @{};
      }
      NSMutableDictionary* resultDic = [NSMutableDictionary dictionary];
      resultDic[@"longitude"] = [NSNumber numberWithDouble:result.location.longitude];
      resultDic[@"latitude"] = [NSNumber numberWithDouble:result.location.latitude];
      resultDic[@"accuracy"] = [NSNumber numberWithInteger:result.confidence];
      if (result.addressDetail) {
        resultDic[@"country"] = result.addressDetail.country;
        resultDic[@"countryCode"] = result.addressDetail.countryCode;
        resultDic[@"city"] = result.addressDetail.city;
        resultDic[@"cityAdcode"] = result.addressDetail.adCode;
        resultDic[@"province"] = result.addressDetail.province;
        resultDic[@"district"] = result.addressDetail.district;
        resultDic[@"street"] = result.addressDetail.streetName;
        resultDic[@"number"] = result.addressDetail.streetNumber;
      }
      resultDic[@"timestamp"] = [NSDate date];
      resultDic[@"pois"] = result.poiList;
      resultDic[@"roads"] = result.roads;
      return resultDic;
    } 

Map component /my.openLocation supports Baidu Map

Important

The cp_change_15200851 baseline version must be 40 or higher.

  1. After extracting MPBaiduMap.framework.zip, add it to the project.

  2. Create the APMobileFramework/MobileRuntime.plist file in the project folder if it does not exist.

  3. Add a new item under the Applications node in MobileRuntime.plist:

    • delegate: APBaiduMapMicroAppDelegate

    • name: 30000050

    • title: Map

    • entry: YES (BOOL)

    image.png