Here are some screenshots from location app utilizing voice searches to find your (points of interest)
You can give the app a POI such as find starbucks and it will show starbucks in your immeadiate area using reverse geocoding, or you can give it an address such as 1600 pensyvania Ave Wash DC and it will use yahoo api to show the exact poi on a google map.
- (void)recognizer:(SKRecognizer *)recognizer didFinishWithResults:(SKRecognition *)results
{
NSLog(@"Got results.");
transactionState = TS_IDLE;
[recordButton setTitle:@"Listen" forState:UIControlStateNormal];
if ([results.results count] > 0)
searchBox.text = [results firstResult];
alternativesDisplay.text = [results.results componentsJoinedByString:@"\n"];
if ([searchBox.text rangeOfString:@"0"].location == 0 || [searchBox.text rangeOfString:@"1"].location == 0 ||
[searchBox.text rangeOfString:@"2"].location == 0 || [searchBox.text rangeOfString:@"3"].location == 0 ||
[searchBox.text rangeOfString:@"5"].location == 0 || [searchBox.text rangeOfString:@"6"].location == 0 ||
[searchBox.text rangeOfString:@"7"].location == 0 || [searchBox.text rangeOfString:@"8"].location == 0 ||
[searchBox.text rangeOfString:@"9"].location == 0)
{
Forward_GeocodingViewController *googleViewController = [[Forward_GeocodingViewController alloc] init];
[googleViewController setQuery:searchBox.text];
[self.navigationController pushViewController:googleViewController animated:YES];
[googleViewController release];
}else {
SearchViewController *searchViewController = [[SearchViewController alloc] init];
[searchViewController searchForString:searchBox.text];
[self.navigationController pushViewController:searchViewController animated:YES];
[searchViewController release];
}
And here is the yahoo api delegate
- (id) initWithDelegate:(id <YahooSearchConnectionDelegate>) delegate
{
if(self = [super init])
{
connDelegate = delegate;
}
return self;
}
/*
Search the Yahoo Local service
*/
- (void) searchByString:(NSString *)searchString
{
NSString *urlString = [NSString stringWithFormat:@"http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=%@&query=%@&latitude=%f&longitude=%f&results=10"
,yahooAPIKey, searchString, [UserData data].currentLocation.coordinate.latitude, [UserData data].currentLocation.coordinate.longitude];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSLog(urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"Connection failed.");
}
}
/*
NSURLConnectionDelegate
*/
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Got search results");
results = [[NSMutableArray alloc] init];
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
//NSLog(theXML);
[theXML release];
if( xmlParser )
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldProcessNamespaces:NO];
[xmlParser setShouldReportNamespacePrefixes:NO];
[xmlParser setShouldResolveExternalEntities:NO];
[xmlParser parse];
[connection release];
}
/*
XML Parser Delegate
*/
- (void)parser :( NSXMLParser *)parser didStartElement :( NSString *)elementName namespaceURI :( NSString *)namespaceURI qualifiedName :( NSString *)qName attributes :( NSDictionary *)attributeDict
{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"Result"])
{
tempResult = [[YahooSearchResult alloc] init];
}
}
- (void)parser :( NSXMLParser *)parser didEndElement :( NSString *)elementName namespaceURI :( NSString *)namespaceURI qualifiedName :( NSString *)qName
{
if ([elementName isEqualToString:@"Result"])
{
// Trim the results
tempResult.title = (NSMutableString *)[tempResult.title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.address = (NSMutableString *)[tempResult.address stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.city = (NSMutableString *)[tempResult.city stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.state = (NSMutableString *)[tempResult.state stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.zip = (NSMutableString *)[tempResult.zip stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.phone = (NSMutableString *)[tempResult.phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.averageRating = (NSMutableString *)[tempResult.averageRating stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.lastReviewIntro = (NSMutableString *)[tempResult.lastReviewIntro stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.yahooURL = (NSMutableString *)[tempResult.yahooURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.businessURL = (NSMutableString *)[tempResult.businessURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.latitude = (NSMutableString *)[tempResult.latitude stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
tempResult.longitude = (NSMutableString *)[tempResult.longitude stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[results addObject:tempResult];
}
}
- (void)parser :( NSXMLParser *)parser foundCharacters :( NSString *)string
{
// Append the string to the current element of a search result
if ([currentElement isEqualToString:@"Title"])
{
[tempResult.title appendString:string];
}
else if ([currentElement isEqualToString:@"Address"])
{
[tempResult.address appendString:string];
}
else if ([currentElement isEqualToString:@"City"])
{
[tempResult.city appendString:string];
}
else if ([currentElement isEqualToString:@"State"])
{
[tempResult.state appendString:string];
}
else if ([currentElement isEqualToString:@"Zip"])
{
[tempResult.zip appendString:string];
}
else if ([currentElement isEqualToString:@"Phone"])
{
[tempResult.phone appendString:string];
}
else if ([currentElement isEqualToString:@"AverageRating"])
{
[tempResult.averageRating appendString:string];
}
else if ([currentElement isEqualToString:@"LastReviewIntro"])
{
[tempResult.lastReviewIntro appendString:string];
}
else if ([currentElement isEqualToString:@"ClickUrl"])
{
[tempResult.yahooURL appendString:string];
}
else if ([currentElement isEqualToString:@"BusinessClickUrl"])
{
[tempResult.businessURL appendString:string];
}
else if ([currentElement isEqualToString:@"Latitude"])
{
[tempResult.latitude appendString:string];
}
else if ([currentElement isEqualToString:@"Longitude"])
{
[tempResult.longitude appendString:string];
}
}
- (void)parserDidEndDocument :( NSXMLParser *)parser
{
[connDelegate yahooSearchConnection:self receivedResult:results];
}
@end
Recent Comments