Reputation: 706
I am building an app that makes use of google places api,i use this url
the desired link doesnt produce any results when i use it in the browser
and i use json to parse the data coming from google places but i get this unusual warning which says NSString may not respond to JSONValue
the code is as follows
-(IBAction)nearbyLocations:(id)sender
{
NSString *url=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=37.329558,122.025002&radius=500&types=atm&sensor=false&key=AIzaSyCIZ8MxCoMsfgj0ytE7azXGfjs_E__2Nhw"];
NSURL *googleRequestURL=[NSURL URLWithString: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
//NSError* error;
NSString *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@",jsonString);
NSDictionary* json =[jsonString JSONValue];
//[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: %@", places);
}
Upvotes: 0
Views: 250
Reputation: 4995
You need a larger radius. In the URL you provided, I changed radius=500
to radius=5000
and it works. New URL. Basically there are no ATMs within 500 meters of that lat/long, but there are ATMs within 5000 meters.
That's one issue. The other issue is in Tsar's comment to your question.
Upvotes: 2