Use Baidu Maps in a mini program

更新时间:
复制 MD 格式

my.getLocation supports the Baidu SDK

  1. Set the option in the initialization method.

    - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    	[LBSmPaaSAdaptorsharedInstance].shouldSkipLBSLocation = YES;
    }
  2. Set the AriverMapEngineDelegate and BMKGeoCodeSearchDelegate protocols for 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 protocol methods.

    #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
    /**
    *Returns the result of the reverse geocoding search.
    *@param searcher The search object.
    *@param result The search result.
    *@param error The error code. For more information, 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", @"The request returned an empty result.");
        
        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;
    } 

The Map widget and my.openLocation support Baidu Maps

Important
  • Use baseline version 10.2.3.

  • If you use the cp_change_15200851 baseline, the version must be cp_change_15200851.40 or later.

  1. Unzip MPBaiduMap.framework.zip and drag the framework into your project.

  2. If the APMobileFramework/MobileRuntime.plist file does not exist in the project folder, create it.

  3. Add an item under the Applications node in MobileRuntime.plist.

    • delegate: APBaiduMapMicroAppDelegate

    • name: 30000050

    • title: Map

    • entry: YES (BOOL)

    image.png