user1003502
user1003502

Reputation:

How to get placemark icons from kml file in MKMapView?

In my GIS app, i want to give custom icons to my pins/locations.In fact I want to utilize the icons whose links are in the kml (I get the placemarks from that kml file).How to "read" this information from the kml file?I am using Apple's KMLViewer. An example from the kml:

<Placemark>
     <name>ATM</name>
     <description>.........Info..........</description><Style>
    <IconStyle>
        <Icon>
            <href>http://www.*****.com/images/categories/atm.png</href>
        </Icon>
    </IconStyle>        
</Style><Point><coordinates>19.8167932033539,41.3254571132609</coordinates></Point></Placemark>

Upvotes: 0

Views: 1217

Answers (1)

MrTJ
MrTJ

Reputation: 13192

KMLViewer uses NSXMLParser to parse the KML file as it is a valid formatted XML format. First study well NSXMLParser and how to implement its delegate to extract the data from the XML. KMLViewer does this as well in KMLParser.m but does not implement the saving of IconStyle element. However it should be not very difficult (and a very good study!) to extend

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
                                        namespaceURI:(NSString *)namespaceURI
                                       qualifiedName:(NSString *)qName
                                          attributes:(NSDictionary *)attributeDict

method of KMLParser and add a new handler for IconStyle. You will have to extend KMLStyle class adding support for placemark icons. Then when you've got the url of the icon, it should be easy to feed it to mapkit instead of the default icon. Good luck!

Upvotes: 1

Related Questions