Try this:
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(latitudeInFloat, longitudeInFloat);
MKMapPoint point = MKMapPointForCoordinate(coord);
NSLog(@"x is %i and y is %i",point.x,point.y);
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(latitudeInFloat, longitudeInFloat);
MKMapPoint point = MKMapPointForCoordinate(coord);
NSLog(@"x is %i and y is %i",point.x,point.y);
cd /Users/lookaflyingdonkey/Documents mkdir SQLiteTutorial cd SQLiteTutorial sqlite3 AnimalDatabase.sql
CREATE TABLE animals ( id INTEGER PRIMARY KEY, name VARCHAR(50), description TEXT, image VARCHAR(255) ); INSERT INTO animals (name, description, image) VALUES ('Elephant', 'The elephant is a very large animal that lives in Africa and Asia', 'http://dblog.com.au/wp-content/elephant.jpg'); INSERT INTO animals (name, description, image) VALUES ('Monkey', 'Monkies can be VERY naughty and often steal clothing from unsuspecting tourists', 'http://dblog.com.au/wp-content/monkey.jpg'); INSERT INTO animals (name, description, image) VALUES ('Galah', 'Galahs are a wonderful bird and they make a great pet (I should know, I have one)', 'http://dblog.com.au/wp-content/galah.jpg'); INSERT INTO animals (name, description, image) VALUES ('Kangaroo', 'Well I had to add the Kangaroo as they are the essence of the Australian image', 'http://dblog.com.au/wp-content/kangaroo.jpg');
#import <UIKit/UIKit.h> @interface Animal : NSObject { NSString *name; NSString *description; NSString *imageURL; } @property (nonatomic, retain) NSString *name; @property (nonatomic, retain) NSString *description; @property (nonatomic, retain) NSString *imageURL; -(id)initWithName:(NSString *)n description:(NSString *)d url:(NSString *)u; @end
#import "Animal.h" @implementation Animal @synthesize name, description, imageURL; -(id)initWithName:(NSString *)n description:(NSString *)d url:(NSString *)u { self.name = n; self.description = d; self.imageURL = u; return self; } @end
#import <UIKit/UIKit.h> #import <sqlite3.h> // Import the SQLite database framework @interface SQLiteTutorialAppDelegate : NSObject { UIWindow *window; UINavigationController *navigationController; // Database variables NSString *databaseName; NSString *databasePath; // Array to store the animal objects NSMutableArray *animals; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @property (nonatomic, retain) NSMutableArray *animals; @end
#import "SQLiteTutorialAppDelegate.h" #import "RootViewController.h" #import "Animal.h" // Import the animal object header @implementation SQLiteTutorialAppDelegate @synthesize window; @synthesize navigationController; @synthesize animals; // Synthesize the aminals array - (void)applicationDidFinishLaunching:(UIApplication *)application { // Setup some globals databaseName = @"AnimalDatabase.sql"; // Get the path to the documents directory and append the databaseName NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; // Execute the "checkAndCreateDatabase" function [self checkAndCreateDatabase]; // Query the database for all animal records and construct the "animals" array [self readAnimalsFromDatabase]; // Configure and show the window [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; } - (void)applicationWillTerminate:(UIApplication *)application { // Save data if appropriate } - (void)dealloc { [animals release]; [navigationController release]; [window release]; [super dealloc]; } -(void) checkAndCreateDatabase{ // Check if the SQL database has already been saved to the users phone, if not then copy it over BOOL success; // Create a FileManager object, we will use this to check the status // of the database and to copy it over if required NSFileManager *fileManager = [NSFileManager defaultManager]; // Check if the database has already been created in the users filesystem success = [fileManager fileExistsAtPath:databasePath]; // If the database already exists then return without doing anything if(success) return; // If not then proceed to copy the database from the application to the users filesystem // Get the path to the database in the application package NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; // Copy the database from the package to the users filesystem [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; [fileManager release]; } -(void) readAnimalsFromDatabase { // Setup the database object sqlite3 *database; // Init the animals Array animals = [[NSMutableArray alloc] init]; // Open the database from the users filessytem if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { // Setup the SQL Statement and compile it for faster access const char *sqlStatement = "select * from animals"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { // Loop through the results and add them to the feeds array while(sqlite3_step(compiledStatement) == SQLITE_ROW) { // Read the data from the result row NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)]; // Create a new animal object with the data from the database Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl]; // Add the animal object to the animals Array [animals addObject:animal]; [animal release]; } } // Release the compiled statement from memory sqlite3_finalize(compiledStatement); } sqlite3_close(database); } @end
SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate]; return appDelegate.animals.count;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } // Set up the cell SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate]; Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row]; [cell setText:animal.name]; return cell; }
#import <UIKit/UIKit.h> @interface AnimalViewController : UIViewController { IBOutlet UITextView *animalDesciption; IBOutlet UIImageView *animalImage; } @property (nonatomic, retain) IBOutlet UITextView *animalDesciption; @property (nonatomic, retain) IBOutlet UIImageView *animalImage; @end
#import "AnimalViewController.h" @implementation AnimalViewController @synthesize animalDesciption, animalImage;
#import <UIKit/UIKit.h> #import "AnimalViewController.h" @interface RootViewController : UITableViewController { AnimalViewController *animalView; } @property(nonatomic, retain) AnimalViewController *animalView; @end
#import "RootViewController.h" #import "SQLiteTutorialAppDelegate.h" #import "Animal.h" @implementation RootViewController @synthesize animalView;
- (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to add the Edit button to the navigation bar. // self.navigationItem.rightBarButtonItem = self.editButtonItem; self.title = @"My Zoo"; }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic -- create and push a new view controller SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate]; Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row]; if(self.animalView == nil) { AnimalViewController *viewController = [[AnimalViewController alloc] initWithNibName:@"AnimalViewController" bundle:nil]; self.animalView = viewController; [viewController release]; } // Setup the animation [self.navigationController pushViewController:self.animalView animated:YES]; // Set the title of the view to the animal's name self.animalView.title = [animal name]; // Set the description field to the animals description [self.animalView.animalDesciption setText:[animal description]]; // Load the animals image into a NSData boject and then assign it to the UIImageView NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]]; UIImage *animalImage = [[UIImage alloc] initWithData:imageData cache:YES]; self.animalView.animalImage.image = animalImage; }
To get my app on onto your iPhone I need some information about your phone. Guess what, there is an app for that!Click on the below link and install and then run the app.This app will create an email. Please send it to me.
Here is my app. To install it onto your phone:
Unzip the archive file. Open iTunes. Drag both files into iTunes and drop them on the Library group. Sync your phone to install the app.
Appirater - Remember your users to Rate your App (iOS)