-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetails.m
194 lines (138 loc) · 4.78 KB
/
Details.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
// Details.m
// BNL
//
// Created by Jia Zhu on 22/09/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "Details.h"
#import "JSON.h"
#import "ShoutViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation Details
@synthesize PUBID;
@synthesize PUBINFO;
@synthesize PUBADDRESS;
@synthesize HOMEPAGE;
@synthesize mapView;
@synthesize textView;
@synthesize scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
textView.layer.cornerRadius = 5;
textView.clipsToBounds = YES;
textView.backgroundColor = UIColor.blackColor;
NSArray* detailsData = [self.PUBID JSONValue];
//choose a random loan
NSDictionary* singleResult = [detailsData objectAtIndex:0];
NSString* name = [singleResult objectForKey:@"NAME"];
NSString* addressDetail = [singleResult objectForKey:@"ADDRESS"];
NSString* SUBURB = [singleResult objectForKey:@"SUBURB"];
NSString* STATE = [singleResult objectForKey:@"STATE"];
NSString* POSTCODE = [singleResult objectForKey:@"POSTCODE"];
NSString* HOMEPAGEURL = [singleResult objectForKey:@"WEB_ADDRESS"];
addressDetail = [addressDetail stringByAppendingString:@", "];
addressDetail = [addressDetail stringByAppendingString:SUBURB];
addressDetail = [addressDetail stringByAppendingString:@", "];
addressDetail = [addressDetail stringByAppendingString:STATE];
addressDetail = [addressDetail stringByAppendingString:@", "];
addressDetail = [addressDetail stringByAppendingString:POSTCODE];
NSString* total = @"";
total = [total stringByAppendingString:name];
total = [total stringByAppendingString:@"\n\n"];
total = [total stringByAppendingString:@"Address:"];
total = [total stringByAppendingString:@"\n"];
total = [total stringByAppendingString:addressDetail];
total = [total stringByAppendingString:@"\n\n"];
total = [total stringByAppendingString:HOMEPAGEURL];
[self.textView setText:total];
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.01;
span.longitudeDelta=0.01;
CLLocationCoordinate2D location = mapView.userLocation.coordinate;
region.span=span;
address = [[NSMutableArray alloc] init];
if(addAnnotation != nil)
{
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
NSNumber* longitude = [singleResult objectForKey:@"LONGITUDE_DEGREE"];
NSNumber* latitude = [singleResult objectForKey:@"LATITUDE_DEGREE"];
location.longitude = longitude.floatValue;
location.latitude = latitude.floatValue;
addAnnotation = [[DetailsAddressAnnotation alloc] initWithCoordinate:location];
[addAnnotation setTitle:name];
[addAnnotation setSubTitle:addressDetail];
region.center=location;
[address addObject:addAnnotation];
[mapView addAnnotations:address];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(847, 800);
[scrollView addSubview:mapView];
[mapView release];
[scrollView addSubview:textView];
[textView release];
[self.view addSubview:scrollView];
[scrollView release];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
@implementation DetailsAddressAnnotation
@synthesize coordinate;
- (void) setTitle:(NSString *)titleValue{
[titleValue retain];
[title release];
title = titleValue;
}
- (void) setSubTitle:(NSString *)subtitleValue{
[subtitleValue retain];
[subtitle release];
subtitle = subtitleValue;
}
- (NSString *)subtitle
{
//please modify to retrieve subtitle from database
return subtitle;
}
- (NSString *)title
{
return title;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c
{
coordinate = c;
return self;
}
@end