if you want to search a particular location using the google api so you can use this .
Step 1: Get the serverKey From the http://console.developers.google.com/ and write the server key as below.
Step 2: #define kGOOGLE_SERVER_KEY @"dsjfdsuiodfdklfjkdlfjkldjfkldjflkds"
Step 3: search For the location and simply call the queryGooglePlaces:(NSString)yourlocationText method.
-(void) queryGooglePlaces: (NSString *) searchText {
NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=%@&key=%@",searchText, kGOOGLE_SERVER_KEY];
NSURL *googleRequestURL=[NSURL URLWithString:url];
NSLog(@"my current url==%@",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 {
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: %@", places);
[self plotPositions:places];
}
[1]: http://console.developers.google.com/
0 Comment(s)