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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:30:15+00:00 2026-06-06T17:30:15+00:00

How do get the phone object from my array to the button on my

  • 0

How do get the phone object from my array to the button on my map annotation call out?

I have the pins loading from a JSON array just fine and I am parsing out the address from the phone number. How do I get the correct phone number to the button when that call out is pushed?

      for(id key in json) {
            id value = [json objectForKey:key];
            NSString *titlePin = [value valueForKey:@"address"];
            NSString *addressPhone = [value valueForKey:@"title"];
            NSString *latitude = [value valueForKey:@"latitude"];
            NSString *longitude = [value valueForKey:@"longitude"];

            NSArray* foo = [addressPhone componentsSeparatedByString: @":"];
            NSString* justAddress = [foo objectAtIndex: 0];
            NSString* phone = [foo objectAtIndex: 1];

            double myLatitude = [latitude doubleValue];
            double myLongitude = [longitude doubleValue];

            MKCoordinateRegion location1;
            location1.center.latitude =myLatitude;
            location1.center.longitude= myLongitude;
            location1.span.longitudeDelta=0.1;
            location1.span.latitudeDelta =0.1;

            MapAnnotation *ann1 =[[[MapAnnotation alloc] init] autorelease];
            ann1.title=[NSString stringWithFormat:@"%@",titlePin];
            ann1.subtitle=[NSString stringWithFormat:@"%@",justAddress];
//EDIT added this line for part of sollution
     ann1.phone=[NSString stringWithFormat:@"%@",phone];
            ann1.coordinate= location1.center;
            [mapView addAnnotation:ann1];
        }
    }
}

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
    MyPin.pinColor = MKPinAnnotationColorPurple;

    UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [advertButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];

    MyPin.rightCalloutAccessoryView = advertButton;
    MyPin.draggable = NO;
    MyPin.highlighted = YES;
    MyPin.animatesDrop=TRUE;
    MyPin.canShowCallout = YES;

    return MyPin;
}

-(void)button:(id)sender {

    // Call the phone number here!!!!!!!
    //NSLog(@"Button action: %@",phone);

}

MapAnnotaion.h

#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>

@interface MapAnnotation : NSObject <MKAnnotation>
{    
    CLLocationCoordinate2D coordinate;
    NSString *title;
    NSString *subtitle;
    NSString *phone;

}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *phone;

@end

MapAnnotaion.m

#import "MapAnnotation.h"

@implementation MapAnnotation

@synthesize coordinate, title, subtitle, phone;

-(void)dealloc
{
    [title release];
    [subtitle release];
    [phone release];
    [super release];
    [super dealloc];
}

@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-06T17:30:16+00:00Added an answer on June 6, 2026 at 5:30 pm

    Part of codes from apple sample code :MapCallouts

    SFAnnotation.h

    #import <MapKit/MapKit.h>
    
    @interface SFAnnotation : NSObject <MKAnnotation>
    {
        UIImage *image;
        NSNumber *latitude;
        NSNumber *longitude;
    }
    
    @property (nonatomic, retain) UIImage *image;
    @property (nonatomic, retain) NSNumber *latitude;
    @property (nonatomic, retain) NSNumber *longitude;
    
    @end
    

    SFAnnotation.m

    #import "SFAnnotation.h"
    
    @implementation SFAnnotation 
    
    @synthesize image;
    @synthesize latitude;
    @synthesize longitude;
    
    
    - (CLLocationCoordinate2D)coordinate;
    {
        CLLocationCoordinate2D theCoordinate;
        theCoordinate.latitude = 37.786996;
        theCoordinate.longitude = -122.419281;
        return theCoordinate; 
    }
    
    - (void)dealloc
    {
        [image release];
        [super dealloc];
    }
    
    - (NSString *)title
    {
        return @"San Francisco";
    }
    
    // optional
    - (NSString *)subtitle
    {
        return @"Founded: June 29, 1776";
    }
    
    @end
    

    where the title is the string shows in the call out’s title

    Edit 1

    -(void)button:(id)sender {
    
    UIButton *button = (UIButton *)sender;
    
    MKAnnotationView *annotationView = button.superview.superview;
    
    MapAnnotaion *mapAnnotaion = annotationView.annotation;
    
    NSLog(@"%@", mapAnnotation.phone);
    
    
    // Call the phone number here!!!!!!!
    //NSLog(@"Button action: %@",phone);
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use ajax call to get some values as JSON object
I have a phone app that trys to GET data from my web api
I want to get phone no of the person from his name which are
I get this from print_r($data) : Array ( [0] => Array ( [0] =>
I have been trying off and on to populate an object from an XML
I want to use CameraCaptureTask on WP7 in order to get image from phone
I have an object that downloads a file from a server, saves it into
I have a heirarchy of classes that get initialized from a database. I am
I've create WebAPI in .net (my first). Using this api to get object from
Can we get phone number of device in j2me? Is it possible or not?

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.