There are so many applications which use location data and display nearby coffee shops , bus stations ,parks, railway stations etc.
In this example we search near by church using latitude,longitude for that we are using google api
-You even need your application's api key.
-You even need your application's api key.
-You can find more search string here:
Example string is here:
- radios is in meters
- location is combination of latitude and longitude
- sensor means whether the place request came from device or not.
- key is application specific ,you need to provide it yourself for your application.
you can copy whole code from here
-(void)ParseXML_of_Google_PlacesAPI
{
NSMutableArray *arrMap = [[NSMutableArray alloc]init];
BOOL isListDisplay = FALSE;
NSString *strSearchWord;
NSString *searchField;
NSString *PlacesURL = @"AIzaSyAgOK0X0Pmwc2BlONmyiHzn5NiKPk_QJqg";
NSString *lattitude = @"41.0335410";
NSString *longitude = @"-74.0475390";
int radious = 500;
@autoreleasepool {
searchField = @"church";
strSearchWord = [[[[[PlacesURL stringByAppendingString:[NSString stringWithFormat:@"location=%@,%@",lattitude,longitude]] stringByAppendingString:[NSString stringWithFormat:@"&radius=%d",radious]]stringByAppendingString:[NSString stringWithFormat:@"&types=%@",searchField ]] stringByAppendingString:[NSString stringWithFormat:@"&sensor=%@",@"false"]] stringByAppendingString:[NSString stringWithFormat:@"&key=%@",@"AIzaSyAgOK0X0Pmwc2BlONmyiHzn5NiKPk_QJqg"]];
NSURL *googlePlacesURL = [NSURL URLWithString:[strSearchWord stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:googlePlacesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
NSURLResponse *resp = nil;
NSError *err = nil;
NSData *xmlData = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];
if(xmlData!=nil){
NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:xmlData options:0 error:nil];
NSArray *arr = [responseDict objectForKey:@"results"];
NSMutableDictionary *new = [[NSMutableDictionary alloc] init];
// new = [[arr objectAtIndex:l] mutableCopy];
[new setObject:searchField forKey:@"type"];
[new setObject:arr forKey:@"Value"];
[arrMap addObject:[NSDictionary dictionaryWithDictionary:new]];
//
if([arr count]>0)
{
isListDisplay = TRUE;
}
}
else{
}
}
}
No comments:
Post a Comment