-1

这是我第一次使用百度API。我在我的项目中实现百度放置自动完成 API 时遇到问题。我正在使用百度开发者链接到http://lbsyun.baidu.com/index.php?title=iossdk

有人请给我一些这方面的教程吗?

我正在关注本教程。关联

但在本教程中我无法接收 json 文件,给我一个错误

{ "Status": 102, "message": "MCODE 参数不存在,移动类型 mcode 必需参数"}

4

2 回答 2

1

看来你应该使用BaiduMapKit的POI搜索​​模块。试试这个。

BMKCitySearchOption *citySearchOption = [[BMKCitySearchOption alloc]init];
citySearchOption.pageIndex = curPage;//here is the page index , you can set it to 0
citySearchOption.pageCapacity = 10;
citySearchOption.city= @"上海";//here is the city where you want to search the road 
citySearchOption.keyword = @"淮海路";//here is the road name or someplace name you want to search
BOOL flag = [_poisearch poiSearchInCity:citySearchOption];
if(flag) {
   _nextPageButton.enabled = true;
   NSLog(@"success");
}
else {
   _nextPageButton.enabled = false;
   NSLog(@"fail");
}
于 2017-03-21T10:43:41.857 回答
0

使用百度 Web API 在百度地图中实现自动完成

- (void)viewDidLoad {
    BaseString = @"http://api.map.baidu.com/place/v2/suggestion?query=";
    ak = @"56dIEtBAp1CU7u8ZMcq8DyUH2mVsn38x";    mcode = @"com.baidu.Baidu-Map-Demo";
    regionkey = @"中国";
    PathString = @"http://api.map.baidu.com/direction/v2/transit?origin=";
    self .mapView .userTrackingMode  = BMKUserTrackingModeFollow;
    // 2. Set the map type    self.mapView.mapType = BMKMapTypeStandard;
    // 3. Set Agent    self.mapView.delegate = self;
    [super viewDidLoad];
    mapView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
    mapView.delegate = self;    anotation = [[BMKPointAnnotation alloc]init];
    destination = [[BMKPointAnnotation alloc]init];
    PathUrl = [[NSURL alloc]init];
    finalPathArray = [[NSMutableArray alloc]init];
    session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    downloadURL = [[NSURL alloc]init];
    path = [[BMKPolyline alloc]init];
    flag = 0;
}

-(void)GetSuggestion: (NSString *)query {
    NSString *stringUrl = [NSString stringWithFormat:@"%@%@&page_size=10&page_num=0&scope=1&region=%@&output=json&ak=%@&mcode=%@",BaseString,query,regionkey,ak,mcode];    stringUrl = [stringUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
    downloadURL = [NSURL URLWithString:stringUrl];
    if (downloadURL != nil) {
        if (DownloadTask != nil) {
            [DownloadTask suspend];
        }
        DownloadTask = [session dataTaskWithURL:downloadURL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
            NSDictionary *AutocompleteData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
            resultArray = AutocompleteData[@"result"];
            tbl_result.hidden = NO;
            [tbl_result reloadData];
        }];
        [DownloadTask resume];
    }
}

MCODE 参数表示您的捆绑包 ID 必须用 url 分隔捆绑包 ID 例如为自动完成写入 url FOR Autocomplete 使用此功能

于 2017-03-28T11:39:38.480 回答