0
我已經在IOS中實施谷歌地點搜索API,並在開發人員控制檯中啓用API,並使用下面的代碼,但它顯示錯誤「此IP,網站或移動應用程序未經授權使用這個API密鑰。從IP地址122.173.223.114接收到的請求,用空指「谷歌地方搜索API在IOS
再生後的API密鑰的節目API密鑰過期後的某個時候它顯示了相同的上述錯誤。請幫助別人。
-(void) queryGooglePlaces: (NSString *) googleType {
// Build the url string to send to Google. NOTE: The kGOOGLE_API_KEY is a constant that should contain your own API key that you obtain from Google. See this link for more info:
// https://developers.google.com/maps/documentation/places/#Authentication
NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%@&types=%@&sensor=true&key=%@", appDel.objLocationManager.location.coordinate.latitude, appDel.objLocationManager.location.coordinate.longitude, [NSString stringWithFormat:@"%i", appDel.currenDist],googleType, kGOOGLE_API_KEY];
//Formulate the string as a URL object.
NSURL *googleRequestURL=[NSURL URLWithString:url];
// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
-(void)fetchedData:(NSData *)responseData {
//parse out the json data
if (responseData==nil) {
}else{
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
//The results from Google will be an array obtained from the NSDictionary object with the key "results".
NSArray* places = [json objectForKey:@"results"];
//Write out the data to the console.
NSLog(@"Google Data: %@", json);
}
}
有一些限制OG谷歌廣場API http://stackoverflow.com/questions/5008689/google-web-search -api-returns-only-the-first-100-results-set – kb920
我使用google –
的替代GMSAutocompleteViewController庫做到了這一點,所以GMSAutocompleteViewController中有沒有任何限制? – kb920