少し前に地図アプリに検索ボックスを追加しました。これは、最小限のオプションで非常に単純な住所検索を行うものでした。
http://maps.googleapis.com/maps/api/geocode/json?address=sydney+grove&sensor=true
このように現在の画面ビューポートを使用して境界パラメーターを追加しました
ブラウザーに貼り付けると結果が返されますが、コードに入力すると常に nil の結果が返されます (jsonResponse は常に nil に等しい)。
-(void) doGeocodingBasedOnStringUsingGoogle:(NSString*) searchString {
GMSCoordinateBounds* bounds=[[self datasource] searchBounds];
//CREATE LOOKUP STRING
NSString *lookUpString = [NSString
stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?
address=%@&bounds=%f,%f|%f,%f&sensor=true",
searchString,
bounds.southWest.latitude,
bounds.southWest.longitude,
bounds.northEast.latitude,
bounds.northEast.longitude];
lookUpString = [lookUpString stringByReplacingOccurrencesOfString:@" "
withString:@"+"];
//SEARCH FOR RESULTS
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSError *error = nil;
NSData *jsonResponse = [NSData dataWithContentsOfURL:[NSURL URLWithString:lookUpString]];
if (jsonResponse) {
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonResponse options:kNilOptions error:&error];
self.searchResults = [jsonDict valueForKey:@"results"];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableview reloadData];
});
});
}
このコードは、境界条件を追加する前は問題なく、削除しても問題ないので、本当にアイデアがありません