Graphics Programs Reference
In-Depth Information
{
CLLocationCoordinate2D coord = [loc coordinate];
// Create an instance of BNRMapPoint with the current data
BNRMapPoint *mp = [[BNRMapPoint alloc] initWithCoordinate:coord
title:[locationTitleField text]];
// Add it to the map view
[worldView addAnnotation:mp];
// Zoom the region to this location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 250, 250);
[worldView setRegion:region animated:YES];
// Reset the UI
[locationTitleField setText:@""];
[activityIndicator stopAnimating];
[locationTitleField setHidden:NO];
[locationManager stopUpdatingLocation];
}
Note that when importing files, you put quotation marks around header files you create
and angled brackets around header files from frameworks. Angled brackets tell the com-
piler, “Only look in the system libraries for this file.” Quotation marks say, “Look in the
directory for this project first, and if you don't find something, then look in the system lib-
raries.” Finally, send the message foundLocation: when a new location is found by
the CLLocationManager . Update the delegate method locationMan-
ager:didUpdateToLocation:fromLocation: in WhereamiViewControl-
ler.m :
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@", newLocation);
// How many seconds ago was this new location created?
NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];
// CLLocationManagers will return the last found location of the
// device first, you don't want that data in this case.
// If this location was made more than 3 minutes ago, ignore it.
if (t < -180) {
// This is cached data, you don't want it, keep looking
return;
}
[self foundLocation:newLocation];
}
Build and run the application. Simulate the location, and then enter a title into the text
field. An annotation will appear on the map at your current location. Tap the pin to show
the title.
Search WWH ::




Custom Search