Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Below is a partial bit of code that I used for the google search APIs. You will need to visit Google Labs API and get a key you can use for search. There is also a GData library, but I had trouble getting it to work for local search so I just went with the HTML/JSON version. My code shows you how to start to decode the JSON that is returned, I cut off the loop since it does a bunch of other stuff.</p> <p>This is the link to the <a href="http://code.google.com/apis/ajaxsearch/documentation/" rel="nofollow noreferrer">Google AJAX APi</a>.</p> <p>I recommend making the API call and then setting a breakpoint where you can look at the dictionary of JSON results you get back to see how it's structured.</p> <pre><code>NSString *searchString = [NSString stringWithFormat:@"http://ajax.googleapis.com/ajax/services/search/local?v=1.0&amp;sll=%f,%f&amp;q=%@", currentLocation.establishedLocation.coordinate.latitude, currentLocation.establishedLocation.coordinate.longitude, searchTerms]; searchString = [searchString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // encode it //NSString *localSearchResults = [NSString stringWithContentsOfURL:[NSURL URLWithString:searchString]]; NSError *error = nil; NSString * localSearchResults = [NSString stringWithContentsOfURL:[NSURL URLWithString:searchString] encoding:NSUTF8StringEncoding error:&amp;error]; if (error != nil) { NSLog(@"Error retrieving map search results in ActivityLocationViewControler::lookupSearchTerms: "); NSLog(@"%s %d %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__); // http://stackoverflow.com/questions/969130/nslog-tips-and-tricks/969272 NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } else { NSData *jsonData = [localSearchResults dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&amp;error]; // we now magically have an array of results from our search. Each result has a bunch of data. NSArray *resultsArray = [[dictionary objectForKey:@"responseData"] objectForKey:@"results"] ; //NSArray *resultsArray = [dictionary objectForKey:@"responseData"]; CLLocationCoordinate2D curCoordinate; NSDictionary *currentResult; BOOL skipThisEntry; for (int i = 0; i &lt; [resultsArray count]; i++) { currentResult = [resultsArray objectAtIndex:i]; // this is a dictionary of this result curCoordinate.latitude = [(NSString *) [currentResult objectForKey:@"lat"] doubleValue] ; curCoordinate.longitude = [(NSString *) [currentResult objectForKey:@"lng"] doubleValue] ; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload