my.getLocation 定位支持百度 SDK
在初始化方法中设置开关。
- (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [LBSmPaaSAdaptorsharedInstance].shouldSkipLBSLocation = YES; }
在页面上设置 AriverMapEngineDelegate 和 BMKGeoCodeSearchDelegate 协议。引入头文件
#import <APMobileLBS/LBSmPaaSAdaptor.h>
。@interfaceViewController : UIViewController<AriverMapEngineDelegate,BMKGeoCodeSearchDelegate> @property (nonatomic, copy) mapReGeocodeCompletedBlockreGeoBlock; @end - (void)viewDidLoad { [superviewDidLoad]; [LBSmPaaSAdaptorsharedInstance].ariverMapEngineDelegate = self; }
实现协议中的方法。
#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 /** *返回反地理编码搜索结果 *@param searcher 搜索对象 *@param result 搜索结果 *@param error 错误号,@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", @"请求结果为空"); 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 组件 /my.openLocation 支持百度地图
重要
cp_change_15200851 基线版本 >= 40。
将 MPBaiduMap.framework.zip 解压后拖入到工程项目中。
工程目录下如果不存在
APMobileFramework/MobileRuntime.plist
文件,则创建该文件。在 MobileRuntime.plist 中的 Applications 节点下新增 Item。
delegate: APBaiduMapMicroAppDelegate
name: 30000050
title: 地图
entry: YES (BOOL)
该文章对您有帮助吗?