From 0273aad7515d6ffb80ae163bbe929ed42624e553 Mon Sep 17 00:00:00 2001 From: Victor Van Hee Date: Mon, 7 Feb 2011 13:16:25 -0800 Subject: [PATCH] object added --- GoogleLocalObject.h | 46 ++++++++++++++++++++++++ GoogleLocalObject.m | 85 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 GoogleLocalObject.h create mode 100644 GoogleLocalObject.m diff --git a/GoogleLocalObject.h b/GoogleLocalObject.h new file mode 100644 index 0000000..f36ddb8 --- /dev/null +++ b/GoogleLocalObject.h @@ -0,0 +1,46 @@ +// +// GoogleLocalObject.h +// BabyMap +// +// Created by Victor C Van Hee on 10/13/10. +// Copyright 2010 __MyCompanyName__. All rights reserved. +// + +#import +#import + +@interface GoogleLocalObject : NSObject { + NSString *title; + NSString *subtitle; + CLLocationCoordinate2D coordinate; + NSString *streetAddress; + NSString *city; + NSString *region; + NSString *phoneNumber; + NSString *country; + NSString *searchTerms; + NSArray *fullAddressArray; + NSString *fullAddressString; +} + +@property (nonatomic, assign) CLLocationCoordinate2D coordinate; +@property (nonatomic, retain) NSString *title; +@property (nonatomic, retain) NSString *subtitle; +@property (nonatomic, retain) NSString *streetAddress; +@property (nonatomic, retain) NSArray *fullAddressArray; +@property (nonatomic, retain) NSString *fullAddressString; +@property (nonatomic, retain) NSString *city; +@property (nonatomic, retain) NSString *region; +@property (nonatomic, retain) NSString *phoneNumber; +@property (nonatomic, retain) NSString *country; +@property (nonatomic, retain) NSString *searchTerms; + +- (id)initWithJsonResultDict:(NSDictionary *)jsonResultDict; + +- (id)initWithTitle:(NSString *)tit subtitle:(NSString *)sub latitude:(double)lat longitude:(double)lng streetAddress:(NSString *)strAdd city:(NSString *)cit region:(NSString *)reg phoneNumber:(NSString *)phone country:(NSString *)coun searchTerms:(NSString *)terms fullAddress:(NSArray *)fullAddrss; + +- (id)initWithTitle:(NSString *)tit latitude:(double)lat longitude:(double)lng streetAddress:(NSString *)strAdd city:(NSString *)cit region:(NSString *)reg phoneNumber:(NSString *)phone country:(NSString *)coun searchTerms:(NSString *)terms fullAddress:(NSArray *)fullAddrss; + +- (id)initWithJsonResultDict:(NSDictionary *)jsonResultDict searchTerms:(NSString *)terms; + +@end diff --git a/GoogleLocalObject.m b/GoogleLocalObject.m new file mode 100644 index 0000000..f43c95c --- /dev/null +++ b/GoogleLocalObject.m @@ -0,0 +1,85 @@ +// +// GoogleLocalObject.m +// +// Created by Victor C Van Hee on 10/13/10. +// Copyright 2010 __MyCompanyName__. All rights reserved. +// + +#import "GoogleLocalObject.h" + +@implementation GoogleLocalObject + +@synthesize title, subtitle, coordinate, streetAddress, phoneNumber, city, region, country, searchTerms, fullAddressArray, fullAddressString; + +- (NSString *)description +{ + NSString *desc = [NSString stringWithFormat:@"title: %@ subtitle: %@ phoneNumber: %@ lat:%f lng:%f streetAddress: %@ city: %@ region: %@ country: %@ searchTerms: %@",title,subtitle,phoneNumber,coordinate.latitude, coordinate.longitude, streetAddress, city, region, country, searchTerms]; + NSLog(@"%@",desc); + return desc; +} + +- (id)initWithTitle:(NSString *)tit subtitle:(NSString *)sub latitude:(double)lat longitude:(double)lng streetAddress:(NSString *)strAdd city:(NSString *)cit region:(NSString *)reg phoneNumber:(NSString *)phone country:(NSString *)coun searchTerms:(NSString *)terms fullAddress:(NSArray *)fullAddrss +{ + self = [super init]; + + if (!self) + return nil; + [self setTitle:tit]; + [self setSubtitle:sub]; + [self setCoordinate:CLLocationCoordinate2DMake(lat, lng)]; + [self setStreetAddress:strAdd]; + [self setCity:cit]; + [self setRegion:reg]; + [self setPhoneNumber:phone]; + [self setCountry:coun]; + [self setSearchTerms:terms]; + [self setFullAddressArray:fullAddrss]; + NSMutableString *result = [[NSMutableString alloc] init]; + for (NSObject *obj in fullAddrss) + { + [result appendString:[obj description]]; + if (obj != [fullAddrss lastObject]) { + [result appendString:@", "]; + } + } + [self setFullAddressString:result]; + return self; +} + +- (id)initWithJsonResultDict:(NSDictionary *)jsonResultDict { + [self initWithJsonResultDict:jsonResultDict searchTerms:@""]; + return self; +} + +- (id)initWithJsonResultDict:(NSDictionary *)jsonResultDict searchTerms:(NSString *)terms +{ + + [self initWithTitle:[jsonResultDict objectForKey:@"titleNoFormatting"] latitude:[[jsonResultDict objectForKey:@"lat"] doubleValue] longitude:[[jsonResultDict objectForKey:@"lng"] doubleValue] streetAddress:[jsonResultDict objectForKey:@"streetAddress"] city:[jsonResultDict objectForKey:@"city"] region:[jsonResultDict objectForKey:@"region"] phoneNumber:[[[jsonResultDict objectForKey:@"phoneNumbers"] objectAtIndex:0] objectForKey:@"number"] country:[jsonResultDict objectForKey:@"country"] searchTerms:terms fullAddress:[jsonResultDict objectForKey:@"addressLines"]]; + return self; +} + +//the below function sets the subtitle automatically to the street address +- (id)initWithTitle:(NSString *)tit latitude:(double)lat longitude:(double)lng streetAddress:(NSString *)strAdd city:(NSString *)cit region:(NSString *)reg phoneNumber:(NSString *)phone country:(NSString *)coun searchTerms:(NSString *)terms fullAddress:(NSArray *)fullAddrss +{ + [self initWithTitle:tit subtitle:strAdd latitude:lat longitude:lng streetAddress:strAdd city:cit region:reg phoneNumber:phone country:coun searchTerms:terms fullAddress:fullAddrss]; + return self; +} + + +- (void) dealloc +{ + NSLog(@"Google Local Object %@ deallocated",[self title]); + [title release]; + [subtitle release]; + [streetAddress release]; + [city release]; + [region release]; + [country release]; + [phoneNumber release]; + [searchTerms release]; + [fullAddressArray release]; + [fullAddressString release]; + [super dealloc]; +} + +@end