-1

This is my first time that I am using Baidu API. I am having problem implementing Baidu places auto-complete API in my project. I am using the Baidu developers link to http://lbsyun.baidu.com/index.php?title=iossdk.

someone please give me to some tutorial in this regard?

i am following this tutorial. link

but in this tutorial i can not receive json file, give me a error

{ "Status": 102, "message": "MCODE parameter is not present, mobile type mcode required parameter"}

Harshil Kotecha
  • 2,846
  • 4
  • 27
  • 41

2 Answers2

1

Seems you should use the POI Search module of BaiduMapKit.Try this.

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");
}
Henson Fang
  • 1,177
  • 7
  • 30
0

Implement AutoComplete In Baidu Map using Baidu 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 parameter means your bundle id must spacify bundle id with urlFor example write url for autocomplete FOR Autocomplete use this function

Harshil Kotecha
  • 2,846
  • 4
  • 27
  • 41
Sakir Sherasiya
  • 1,562
  • 1
  • 17
  • 31