Hallo,
Ik zit met het volgende. Ik probeer een iphone app te maken met een store locator, alleen lopen we tegen het volgende aan.
We hebben een mapview, hier worden doormiddel van een xml bestand 4 annotations ingeladen. Het probleem komt wanneer je details van deze annotation wilt bekijken. Op dit moment wordt de hele tijd dezelfde detailview geladen, dit is ook geen probleem. Maar in die detailview moet de tekst aangepast worden zodat deze overeenkomt met de aangeklikte annotation. Op dit moment hebben we gebruik gemaakt van de code KMLViewer van apple developer library om de annotations uit een xml bestand te halen en weer te geven op de mapview.
Onze detail view ziet er als volgt uit:
detailviewcontroller.m
Map view
Op dit moment weet ik even niet meer waar ik moet beginnen. Een duw in de juiste richting zou fijn zijn!!
Alvast bedankt
Ik zit met het volgende. Ik probeer een iphone app te maken met een store locator, alleen lopen we tegen het volgende aan.
We hebben een mapview, hier worden doormiddel van een xml bestand 4 annotations ingeladen. Het probleem komt wanneer je details van deze annotation wilt bekijken. Op dit moment wordt de hele tijd dezelfde detailview geladen, dit is ook geen probleem. Maar in die detailview moet de tekst aangepast worden zodat deze overeenkomt met de aangeklikte annotation. Op dit moment hebben we gebruik gemaakt van de code KMLViewer van apple developer library om de annotations uit een xml bestand te halen en weer te geven op de mapview.
Onze detail view ziet er als volgt uit:
detailviewcontroller.m
C:
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
| #import "DetailViewController.h" @implementation DetailViewController @synthesize address; // Implement viewDidLoad to do additional setup after loading the view, typically from a nib - (void)viewDidLoad { TabbedCalculationAppDelegate *appDelegate = (TabbedCalculationAppDelegate *)[[UIApplication sharedApplication] delegate]; address.text = appDelegate.addressInput1 ; [super viewDidLoad]; } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } |
Map view
C:
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
| #import "locator.h" #import "DetailViewController.h" @implementation locator @synthesize map, detailViewController, rightButton, customPinView; - (void)viewDidLoad { [super viewDidLoad]; // create a custom navigation bar button and set it to always says "Back" UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title = @"Back"; self.navigationItem.backBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release]; // Locate the path to the route.kml file in the application's bundle // and parse it with the KMLParser. NSString *path = [[NSBundle mainBundle] pathForResource:@"branches" ofType:@"kml"]; kml = [[KMLParser parseKMLAtPath:path] retain]; // Add all of the MKOverlay objects parsed from the KML file to the map. NSArray *overlays = [kml overlays]; [map addOverlays:overlays]; // Add all of the MKAnnotation objects parsed from the KML file to the map. NSArray *annotations = [kml points]; [map addAnnotations:annotations]; // Walk the list of overlays and annotations and create a MKMapRect that // bounds all of them and store it into flyTo. MKMapRect flyTo = MKMapRectNull; for (id <MKOverlay> overlay in overlays) { if (MKMapRectIsNull(flyTo)) { flyTo = [overlay boundingMapRect]; } else { flyTo = MKMapRectUnion(flyTo, [overlay boundingMapRect]); } } for (id <MKAnnotation> annotation in annotations) { MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate); MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0); if (MKMapRectIsNull(flyTo)) { flyTo = pointRect; } else { flyTo = MKMapRectUnion(flyTo, pointRect); } } // Position the map so that all overlays and annotations are visible on screen. MKCoordinateRegion mapRegion; mapRegion.center.latitude = 51.522416; mapRegion.center.longitude = 5.141602; mapRegion.span.latitudeDelta = 5; mapRegion.span.longitudeDelta = 5; [map setRegion:mapRegion animated:YES]; } #pragma mark MKMapViewDelegate - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay { return [kml viewForOverlay:overlay]; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { // if it's the user location, just return nil. if ([annotation isKindOfClass:[MKUserLocation class]]) return nil; // handle custom annotations // // try to dequeue an existing pin view first static NSString* BridgeAnnotationIdentifier = @"bridgeAnnotationIdentifier"; MKPinAnnotationView* pinView = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:BridgeAnnotationIdentifier]; if (!pinView) { // if an existing pin view was not available, create one customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease]; customPinView.pinColor = MKPinAnnotationColorPurple; customPinView.animatesDrop = YES; customPinView.canShowCallout = YES; // add a detail disclosure button to the callout which will open a new view controller page // // note: you can assign a specific call out accessory view, or as MKMapViewDelegate you can implement: // - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control; // rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; customPinView.rightCalloutAccessoryView = rightButton; return customPinView; }else{ return pinView;} return nil; } #pragma mark - #pragma mark MKMapViewDelegate - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { { if (view.annotation == mapView.userLocation) return; rightButton = (DetailViewController *)view.annotation; //show detail view using buttonDetail... } // the detail view does not want a toolbar so hide it [self.navigationController setToolbarHidden:YES animated:YES]; [self.navigationController pushViewController:self.detailViewController animated:YES]; } - (void)viewDidUnload { self.detailViewController = nil; } - (void)dealloc { [detailViewController release]; [super dealloc]; } @end |
Op dit moment weet ik even niet meer waar ik moet beginnen. Een duw in de juiste richting zou fijn zijn!!
Alvast bedankt