Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:10:12+00:00 2026-06-18T01:10:12+00:00

I am trying to load my Map which I created with a kml File

  • 0

I am trying to load my Map which I created with a kml File in Google-Maps. The Google Maps Link. I have to say it is only an example, but it is the same principle.

The easiest way is to load in a WebView, but that is ugly in my eyes.

Thank you for reading my Question!

Best regards CTS

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:10:13+00:00Added an answer on June 18, 2026 at 1:10 am

    To load a KML into a MKMapView:

    1. Add the necessary frameworks (MapKit.framework and CoreLocation.framework) to your target;

    2. Load and parse the KML;

    3. Create your annotations on the basis of the KML; and

    4. Set your map’s region to encompass the annotations.

    Thus, that might look like:

    #import <MapKit/MapKit.h>
    
    - (void)loadKml:(NSURL *)url
    {
        // parse the kml
    
        Parser *parser = [[Parser alloc] initWithContentsOfURL:url];
        parser.rowElementName = @"Placemark";
        parser.elementNames = @[@"name", @"Snippet", @"coordinates", @"description"];
        parser.attributeNames = nil;
        [parser parse];
    
        // add annotations for each of the entries
    
        for (NSDictionary *locationDetails in parser.items)
        {
            MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
            annotation.title = locationDetails[@"name"];
            annotation.subtitle = locationDetails[@"Snippet"];
            NSArray *coordinates = [locationDetails[@"coordinates"] componentsSeparatedByString:@","];
            annotation.coordinate = CLLocationCoordinate2DMake([coordinates[1] floatValue], [coordinates[0] floatValue]);
            [self.mapView addAnnotation:annotation];
        }
    
        // update the map to focus on the region that encompasses all of your annotations
    
        MKCoordinateRegion region;
        if ([self.mapView.annotations count] > 1)
        {
            region = [self regionForAnnotations:self.mapView.annotations];
            region = MKCoordinateRegionMake(region.center, MKCoordinateSpanMake(region.span.latitudeDelta * 1.05, region.span.longitudeDelta * 1.05));  // expand the region by 5%
        }
        else
        {
            id<MKAnnotation> annotation = self.mapView.annotations[0];
            region = MKCoordinateRegionMakeWithDistance(annotation.coordinate, 100.0, 100.0);
        }
        [self.mapView setRegion:region animated:YES];
    }
    

    My Parser class is just a NSXMLParser subclass that I’ve written that will create an array of items one per occurrence of rowElementName, and for each row, it will grab the elements listed in the elementNames array.

    Parser.h:

    #import <Foundation/Foundation.h>
    
    @interface Parser : NSXMLParser
    
    @property (nonatomic, strong) NSString *rowElementName; // this is the element name that identifies a new row of data in the XML
    @property (nonatomic, strong) NSArray *attributeNames;  // this is the array of attributes we might want to retrieve for that element name
    @property (nonatomic, strong) NSArray *elementNames;    // this is the list of sub element names for which we're retrieving values
    
    @property (nonatomic, strong) NSMutableArray *items;    // after parsing, this is the array of parsed items
    
    @end
    

    Parser.m:

    #import "Parser.h"
    
    @interface Parser () <NSXMLParserDelegate>
    
    @property (nonatomic, strong) NSMutableDictionary *item;     // while parsing, this is the item currently being parsed
    @property (nonatomic, strong) NSMutableString *elementValue; // this is the element within that item being parsed
    
    @end
    
    @implementation Parser
    
    - (id)initWithContentsOfURL:(NSURL *)url
    {
        self = [super initWithContentsOfURL:url];
    
        if (self)
        {
            self.delegate = self;
        }
    
        return self;
    }
    
    - (id)initWithData:(NSData *)data
    {
        self = [super initWithData:data];
    
        if (self)
        {
            self.delegate = self;
        }
    
        return self;
    }
    
    - (id)initWithStream:(NSInputStream *)stream
    {
        self = [super initWithStream:stream];
    
        if (self)
        {
            self.delegate = self;
        }
    
        return self;
    }
    
    #pragma mark - NSXMLParserDelegate methods
    
    - (void)parserDidStartDocument:(NSXMLParser *)parser
    {
        self.items = [[NSMutableArray alloc] init];
    
        if (!self.rowElementName)
            NSLog(@"%s Warning: Failed to specify row identifier element name", __FUNCTION__);
    }
    
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
    {
        if ([elementName isEqualToString:self.rowElementName])
        {
            self.item  = [[NSMutableDictionary alloc] init];
    
            for (NSString *attributeName in self.attributeNames)
            {
                id attributeValue = [attributeDict valueForKey:attributeName];
                if (attributeValue)
                    [self.item setObject:attributeValue forKey:attributeName];
            }
        }
        else if ([self.elementNames containsObject:elementName])
        {
            self.elementValue = [[NSMutableString alloc] init];
        }
    }
    
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
    {
        if (self.elementValue)
        {
            [self.elementValue appendString:string];
        }
    }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        if ([elementName isEqualToString:self.rowElementName])
        {
            [self.items addObject:self.item];
            self.item = nil;
        }
        else if ([self.elementNames containsObject:elementName])
        {
            [self.item setValue:self.elementValue forKey:elementName];
            self.elementValue = nil;
        }
    }
    
    @end
    

    Finally, the only other utility method that my loadKml uses is regionForAnnotations, which defines a region based upon a series of annotations. Rob Mooney wrote a simple routine to do that:

    - (MKCoordinateRegion)regionForAnnotations:(NSArray *)annotations {
    
        CLLocationDegrees minLat = 90.0;
        CLLocationDegrees maxLat = -90.0;
        CLLocationDegrees minLon = 180.0;
        CLLocationDegrees maxLon = -180.0;
    
        for (id <MKAnnotation> annotation in annotations) {
            if (annotation.coordinate.latitude < minLat) {
                minLat = annotation.coordinate.latitude;
            }
            if (annotation.coordinate.longitude < minLon) {
                minLon = annotation.coordinate.longitude;
            }
            if (annotation.coordinate.latitude > maxLat) {
                maxLat = annotation.coordinate.latitude;
            }
            if (annotation.coordinate.longitude > maxLon) {
                maxLon = annotation.coordinate.longitude;
            }
        }
    
        MKCoordinateSpan span = MKCoordinateSpanMake(maxLat - minLat, maxLon - minLon);
    
        CLLocationCoordinate2D center = CLLocationCoordinate2DMake((maxLat - span.latitudeDelta / 2), maxLon - span.longitudeDelta / 2);
    
        return MKCoordinateRegionMake(center, span);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load a kml on a google map but I cant do
I'm trying to load a map generated with Google Maps API on a site.
I am trying to dynamically load a KML file into a map depending on
I'm trying to load a remote file and I have to use HttpClient.execute which
Trying to load a small .txt file into mysql but get all my data
Im trying to load a .txt file into a 2D array which i can
I am trying to load a StageWebView with the Google Maps Javascript API inside
I am trying to use the google maps javascript API to map an address
I'm trying to make a page which includes a static Google map. When the
I am trying to load google map to uiwebview after performing a query using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.