- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// 緯度・経度取得
CLLocationDegrees latitude = newLocation.coordinate.latitude;
CLLocationDegrees longitude = newLocation.coordinate.longitude;
// APIからベニューリストを取得
NSString *urlString = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/search?ll=%f,%f&limit=30&client_id=ICIWPLPZATTTPYV0YBSVB4AQCF2PVXUWKHS3ZT1BURV0PS02&client_secret=T5SEMJSHYURT5UGERXLZNCUGI1QZ1JJHWBYN2XLDWK3FQUFN&v=20140629", latitude, longitude];
//NSLog(@"urlString = %@", urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSString *response = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSData *jsonData = [response dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
// エラーコードをログに出力
NSInteger errorCode = [[[jsonDic objectForKey:@"meta"] objectForKey:@"code"] integerValue];
NSLog(@"errorCode = %d", errorCode);
// 結果取得
NSArray *venues = [[jsonDic objectForKey:@"response"] objectForKey:@"venues"];
venues_ = [venues mutableCopy];
[self.tableView reloadData];
}
NSError *error;
NSDictionary *jsonDic = [NSJSONSerialization
JSONObjectWithData:jsonData
options:kNilOptions
error:&error];
if (!error) {
// エラーコードをログに出力
if ([jsonDic count] == 0) {
NSLog(@"don't access it as the index is out of bounds");
return;
}else{
NSInteger errorCode = [[[jsonDic objectForKey:@"meta"] objectForKey:@"code"] integerValue];
NSLog(@"errorCode = %ld", (long)errorCode);
// 結果取得
NSArray *venues = [[jsonDic objectForKey:@"response"] objectForKey:@"venues"];
venues_ = [venues mutableCopy];
}
}else{
NSLog(@"Error: %@", [error localizedDescription]);
}
if (jsonData == nil) {
NSLog(@"ERROR!");
}else{
NSDictionary *jsonDic = [NSJSONSerialization
JSONObjectWithData:jsonData
options:kNilOptions
error:&error];
if (!error) {
// エラーコードをログに出力
if ([jsonDic count] == 0) {
NSLog(@"don't access it as the index is out of bounds");
return;
}else{
NSInteger errorCode = [[[jsonDic objectForKey:@"meta"] objectForKey:@"code"] integerValue];
NSLog(@"errorCode = %ld", (long)errorCode);
// 結果取得
NSArray *venues = [[jsonDic objectForKey:@"response"] objectForKey:@"venues"];
venues_ = [venues mutableCopy];
}
}else{
NSLog(@"Error: %@", [error localizedDescription]);
}
}
S | M | T | W | T | F | S |
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
ファン申請 |
||