Getting xml data in DetailView from a map view (Iphone IOS)

旧城冷巷雨未停 提交于 2019-12-06 21:50:41

Please have a look at the interface of the KMLPlacemark in KMLParser, there you can see what is exactly parsed and stored of an xml placemark element. For example the address is missing. So you will have to add all the information you want the parser to gather by implementing the fields in the KMLPlacemark class and alter the KMLParser methods:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName ...
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName ...

as well as some parts of the KMLPlacemark implementation. To fill the new fields with the parser you'll have to write methods like the - (void)beginName and - (void)endName. It will get a bit tricky when the elements you want to parse have children.

It could be helpful to split the KMLParser file into several files which contain one class each.

If you have achieved that and your placemark contains all the needed details you can catch the tap on an annotation with the MKMapViewDelegate protocol. Implement didDeselectAnnotationView, which could look like this:

- (void) mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
    // implementation example of placemarkForAnnotation below
    KMLPlacemark * placemark = [kml placemarkForAnnotation:view.annotation];

    MyDetailViewController * myDetailViewController = [[MyDetailViewController alloc] initWithPlacemark:placemark];

    [self presentModalViewController:myDetailViewController animated:YES];

    [myDetailViewController release];
}

In KMLParser add

- (KMLPlacemark *)placemarkForAnnotation:(id <MKAnnotation>)point
{
    // Find the KMLPlacemark object that owns this point and return it
    for (KMLPlacemark *placemark in _placemarks) {
        if ([placemark point] == point)
            return placemark;
    }
    return nil;
}

Hope I could point you in the right direction. It'll be some work ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!