Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

robert cioffi
robert cioffi
3,466 Points

GoogleMaps SDK, search anything, not just from types

Hi,

I recently wrote a Map App with the code from: http://www.raywenderlich.com/13160/using-the-google-places-api-with-mapkit (which is a really great tutorial if you want to embed Maps into your apps)

But there is a specific part of the code (below) that does a JSON request for getting info on items around your location (which is limited to Googles 255 types), I want to change this so I can have a user type in a specific name of a restaurant or other item and have google search the area, does anyone know how to change the url "stringWithFormat" below to do this? I think there may be a parameter named "q", but can't figure out the right format.

pragma mark - get Google search data from internet

-(void) queryGooglePlaces: (NSString *) googleType { NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%@&types=%@&sensor=true&key=%@", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:@"%i", currenDist], googleType, @"AIzaSyC8Zz6aLGTro-cDYdtfsP2YramG859AC9A"];

//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];
});

}

1 Answer

robert cioffi
robert cioffi
3,466 Points

nevermind, found that type is just an optional parameter of which there are quite a few listed at: https://developers.google.com/places/documentation/search find Optional parameters section

so in the string I mentioned above you would switch "types" for "keyword"

so simple!