2013-10-22 5 views
2

지난 며칠 동안 Google 지역 정보 자동 완성 기능이 내 앱에서 작동하도록 고심하고 있었고, 내가 무엇을 하든지 항상 REQUEST_DENIED 오류가 발생했습니다.iOS에서 Google 지역 정보 API 자동 완성

구현을 위해 Google의 '튜토리얼'을 따랐으며 Places API가 사용 설정되었으며 API 키에 올바른 번들 ID가 있고 브라우저 ID로 테스트 한 결과 성공하지 못했습니다.

저는 키와 관련이 있다고 확신합니다. 흥미롭게도 앱의 Android 버전에서 서비스는 브라우저 키로 작동합니다. 그리고 브라우저에서 분명히, 그것은 그 열쇠와도 작동합니다. 나는이 같은 몇 가지 질문이 여기가 알고

NSURL *url = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/autocomplete/"]; 

    NSDictionary *params = @{@"input" : [input stringByReplacingOccurrencesOfString:@" " withString:@"+"], 
          @"location" : [NSString stringWithFormat:@"%f,%f", searchCoordinate.latitude, searchCoordinate.longitude], 
          @"sensor" : @(true), 
//       @"language" : @"pt_BR", 
//       @"types" : @"(regions)", 
//       @"components" : @"components=country:br", 
          @"key" : GOOGLE_API_KEY}; 

    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; 
    [httpClient setParameterEncoding:AFFormURLParameterEncoding]; 

    [httpClient getPath:@"json" 
      parameters:params 
       success:^(AFHTTPRequestOperation *operation, id responseObject) { 

       NSDictionary *JSON = [[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil] dictionaryWithoutNulls]; 
       if (completion) { 
        completion(JSON[@"predictions"]); 
       } 

       } 
       failure:^(AFHTTPRequestOperation *operation, NSError *errorResponse) { 
       NSLog(@"[HTTPClient Error]: %@ for URL %@", [errorResponse localizedDescription], [[[operation request] URL] path]); 
       }]; 

:

이 내가 실험 두 개의 열쇠 :

Google APIs Console

그리고 이것은 AFNetworking를 사용하여 내 구현 코드 하지만 일부는 오래되었으며 Places API 페이지에서 볼 수 있듯이 Google 자체에서 두 플랫폼 모두에서 예제를 게시하므로 Android API 나 iOS에서는 Android API 나 iOS에서 Places API가 작동하지 않는다고 말합니다. https://developers.google.com/places/documentation/autocomplete

해결 방법 현재 전체 주소를 입력 할 때 잘 작동하지만 반 형구가 끔찍한 Apple의 지오 코딩 시스템이 사용됩니다. 이것은 전혀 좋지 않습니다. Google의 API를 사용하고 싶습니다.

답변

2

알았습니다.

paramenter sensor@"true" 또는 @"false", 그리고 @(true) 또는 @(false) 중 하나가 나타납니다.

레코드의 경우 실제로 사용 된 API 키는 iOS 키가 아닌 브라우저 키입니다.

1

기본 URL이 @"https://maps.googleapis.com/"httpClient을 초기화하고 경로 /maps/api/place/autocomplete/json을 가져와야합니다. 기본 URL - 호스트 만, 경로의 다른 부분을 차지하지 않으므로 URL "https://maps.googleapis.com/json"에 대한 요청을 받게됩니다.

+0

하지만 내 문제가 해결되지 않았다. 나는 여전히'REQUEST_DENIED'를 얻는다. 두 키를 모두 사용해보십시오. – Guilherme

관련 문제