Firstly, sorry for my English... I want to write a program which is going to calculate distances between two cities. For example, in UITextField we write Paris, and in the second UITextField we write the second , "London. And We have a base of longitude s and latitude s of all Cities. Our program has distance formula which uses these four numbers. We know this formula.
When the user insert a name in UITextField i want to TAKE THIS .text AND COMPARE IT WITH OUR BASE. How to do that?? I can do a program like this but it`s ....stupid:
@interface City : UIViewController{
IBOutlet UITextField *city1;
IBOutlet UITextField *city2;
}
@property (nonatomic, retain) IBOutlet UITextField *city1;
@property (nonatomic, retain) IBOutlet UITextField *city2;
-(void) calculate;
@end
#import "City.h"
@implementation City
@synthesize city1, city2;
-(void) viewDidLoad
{
// to check changes in textfields i`m using NSTimer, I know it`s stupid but I haven`t learned how to make it in different way
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(calculate) userInfo:nil repeats:YES];
}
-(void) obliczenia
{
double distance;
if([city1 is EqualToString:@"Paris"] && [city2 is EqualToString:@"London"])
{
double Paris_lat = x1;
double Paris_lon = y1;
double London_lat = x2;
double London_lon = y2;
distance =...; // we know the formula for distance but this is not important for now.
// distance shows in some label but this is not a point of my problem.
}
}
It runs but when we have few cities. But when we have thousand cities, writing code would be a nonsens.
I am starting with iPhone programming. Thank you for patience and please, help me. It s very important but I can't find a solution.