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 9312051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:32:08+00:00 2026-06-19T01:32:08+00:00

There are a few tutorials and questions on this, but I’m not knowledgeable enough

  • 0

There are a few tutorials and questions on this, but I’m not knowledgeable enough yet to understand how to implement them into my particular app. I get JSON annotation data from a URL and parse it and add each annotation in for loop. I want to add a link on each annotation to open Maps for directions.

Here’s my ViewController.H

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MapKit/MapKit.h>

//MAP Setup
@interface ViewController : UIViewController <MKMapViewDelegate>

//map setup
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (nonatomic, strong) NSMutableData *downloadData;
//- (IBAction)refreshTapped:(id)sender;


@end

and my ViewController.m

- (void)viewDidLoad
{
    ////////////////////////
    //Connection to download JSON map info
    ////////////////////////
    self.downloadData = [NSMutableData new];

    NSURL *requestURL2 = [NSURL URLWithString:@"http:OMITTED"];
    NSURLRequest *request = [NSURLRequest requestWithURL:requestURL2];
    NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];

    //scroller
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320,900)];

    [super viewDidLoad];    

//Map
    [self.mapView.userLocation addObserver:self
                                forKeyPath:@"location"
                                   options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
                                   context:nil];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [self.downloadData appendData:data];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    id parsed = [NSJSONSerialization JSONObjectWithData:_downloadData options:kNilOptions error:nil];

    ////////////////////////
    //Iterating and adding annotations
    ////////////////////////
    for (NSDictionary *pointInfo in parsed)
    {
        NSLog([pointInfo objectForKey:@"name"]);
        double xCoord = [(NSNumber*)[pointInfo objectForKey:@"lat"] doubleValue];
        double yCoord = [(NSNumber*)[pointInfo objectForKey:@"lon"] doubleValue];
        CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(xCoord, yCoord);


        MKPointAnnotation *point = [MKPointAnnotation new];
        point.coordinate = coords;
        point.title = [pointInfo objectForKey:@"name"];

        [self.mapView addAnnotation:point];// or whatever your map view's variable name is
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//centers map on user loc and then allows for movement of map without re-centering on userlocation check.
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
    if ([self.mapView showsUserLocation])
    {
        MKCoordinateRegion region;
        region.center = self.mapView.userLocation.coordinate;

        MKCoordinateSpan span;
        span.latitudeDelta  = .50; // Change these values to change the zoom
        span.longitudeDelta = .50;
        region.span = span;

        [self.mapView setRegion:region animated:YES];

        self.mapView.showsUserLocation = NO;}
}

- (void)dealloc
{
    [self.mapView.userLocation removeObserver:self forKeyPath:@"location"];
    [self.mapView removeFromSuperview]; // release crashes app
    self.mapView = nil;
}

@end
  • 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-19T01:32:09+00:00Added an answer on June 19, 2026 at 1:32 am

    Launching the Maps App of the Location Awareness Programming Guide says:

    If you would prefer to display map information in the Maps app as opposed to your own app, you can launch Maps programmatically using one of two techniques:

    In iOS 6 and later, use an MKMapItem object to open Maps.
    In iOS 5 and earlier, create and open a specially formatted map URL as described in Apple URL Scheme Reference.
    The preferred way to open the Maps app is to use the MKMapItem class. This class offers both the openMapsWithItems:launchOptions: class method and the openInMapsWithLaunchOptions: instance method for opening the app and displaying locations or directions.

    For an example showing how to open the Maps app, see “Asking the Maps App to Display Directions.”

    So, you should:

    1. Make sure to define your view controller to be the delegate for your map view;

    2. Write a viewForAnnotation that turns on canShowCallout and turns on the callout accessory view:

      - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
      {
          if ([annotation isKindOfClass:[MKUserLocation class]])
              return nil;
      
          MKAnnotationView* annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
                                                                          reuseIdentifier:@"MyCustomAnnotation"];
      
          annotationView.canShowCallout = YES;
          annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
      
          return annotationView;
      }
      
    3. Then write a calloutAccessoryControlTapped method that opens the maps as outlined above, based upon what versions of iOS you’re supporting, e.g., for iOS 6:

      - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
      {
          id <MKAnnotation> annotation = view.annotation;
          CLLocationCoordinate2D coordinate = [annotation coordinate];
          MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
          MKMapItem *mapitem = [[MKMapItem alloc] initWithPlacemark:placemark];
          mapitem.name = annotation.title;
          [mapitem openInMapsWithLaunchOptions:nil];
      }
      

      I don’t know what additional geographic information your have in your KML, but you can presumably fill in the addressDictionary as you see fit.


    In answer to your follow-up question about how to use the addressDictionary parameter of the MKPlacemark initializer method, initWithCoordinate, if you had NSString variables for the street address, the city, the state, the zip, etc., it would look like:

    NSDictionary *addressDictionary = @{(NSString *)kABPersonAddressStreetKey : street,
                                        (NSString *)kABPersonAddressCityKey   : city,
                                        (NSString *)kABPersonAddressStateKey  : state,
                                        (NSString *)kABPersonAddressZIPKey    : zip};
    

    For this to work, you have to add the appropriate framework, AddressBook.framework, to your project and import the header in your .m file:

    #import <AddressBook/AddressBook.h>
    

    The real question, though, was how to set the name for the MKMapItem so it doesn’t show up as “Unknown Location” in the maps app. That’s as simple as setting the name property, probably just grabbing the title from your annotation:

    mapitem.name = annotation.title;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there are a few questions like this on SOF, but I
I know there are a few questions floating around here on the subject, but
I've asked a few questions on this topic before. Before we're able to implement
I'm new in Allegro 5, I've written some code with the few tutorials there
I know how to use locks in my app, but there still few things
There are a few examples on unobtrusive events for pure JS. Most of questions
I'm looking to implement my first Android database, but I have so many questions
I've been reading questions on Stack Overflow for a few weeks now... this'll be
I know there have been a lot of questions of this, however those were
I'm searching for this for quite some time now. I saw few similar questions

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.