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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:39:59+00:00 2026-06-07T10:39:59+00:00

I have a .xib file where the user can enter a location name of

  • 0

I have a .xib file where the user can enter a location name of a place in a UITextField and click search. Then another .xib file will load where the user will see a MapView object with the location on the map.

I made a custom init method where I pass the string as follows when the user clicks the button:

AddLocViewController *locView = [[AddLocViewController alloc] initWithNibName:nil bundle:nil customLoc:textLoc.text];
[self presentModalViewController:locView animated:YES];

In the new ViewController class called AddLocViewController.m the init method and viewDidLoad is as following:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil customLoc:(NSString*)_loc
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        stringLoc1 = _loc;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];    
    [self showAddress];
}

Here [self showAddress] calls a method to display the contents on the mapView object, The showAddress method works perfectly if I have a UITextField taking input and clicking a button to set the value to a NSString object stringLoc and using that in showAddress method:

- (void) showAddress
{
    MKCoordinateRegion region;
MKCoordinateSpan span;

span.latitudeDelta=0.01f;
span.longitudeDelta=0.01f;

    stringLoc1 = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                       [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:stringLoc1]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];

double aLatitude = 0.0;
double aLongitude = 0.0;

if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
    aLatitude = [[listItems objectAtIndex:2] doubleValue];
    aLongitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
    [addressField setText: @"Address Location error"];
    return;
}

[addressField resignFirstResponder];

CLLocationCoordinate2D location = {latitude: aLatitude, longitude:aLongitude};

region.span=span;
region.center.latitude = aLatitude;
    region.center.longitude = aLongitude;

    if(addAnnotation != nil) {
    [mapView removeAnnotation:addAnnotation];
    //[addAnnotation release];
    addAnnotation = nil;
}

    addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
    [mapView addAnnotation: addAnnotation];

[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
}

Please help me pass parameter here to this class and use the showAddress method appropriately because it only now shows the proper location when a location is searched from within the class and does not show the proper location when instantiated.

  • 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-07T10:40:01+00:00Added an answer on June 7, 2026 at 10:40 am

    Here you overwrite stringLoc1 with the content of the address field:
    It is overwritten regardless of its initial value. If the textField is empty then it is overwirtten with an empty string.

    stringLoc1 = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                           [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    

    I am not sure what the best solution is in the context of your remaining code. But this should work:

    NSString *currentLoc;
    
    if (addressField.text && ([addressField.text length] == 0)) {
      currentLoc = addressFiled.text;
      stringLoc1 = addressField.text; // this line will set the current value as default value for the next call of the method; unless a new init call comes in between.
    }
    else
      currentLoc = stringLoc1; 
    
    
        currentLoc = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                               [currentLoc  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:currentLoc ]];
    

    I am sure there are smarter ways of doing that. But this should work with minimal changes to the view lines of code that you shared with us.

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

Sidebar

Related Questions

I have basic *.xib file, which have NSView. How can I use another nib
I have a XIB file with a UITextView, which I'm associating with a UITextView*
I have a XIB file with my controls in it, loaded in the Interface
In my xib file I have some View. And I have PainView class (UIView).
I have created a custom view with a XIB file and are loading the
I have made a UIViewController subclass without a .xib file, thinking I would not
I have a UIViewController I am loading from a xib file and pushing onto
everyone. I have some labels that I draw them in the xib file, and
I have a picker View in one xib file, and a map View in
I have a .xib file for my viewController. It contains a TableView and a

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.