Annotation on Map is "Current Location"


#1

I have looked at other peoples code and I have the same thing. I am using the simulator so I don;'t know if that is my issue:

[code]//WhereamiViewController.m
#import “WhereamiViewController.h”
#import “BNRMapPoint.h”

@implementation WhereamiViewController

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if(self){
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}

return self;

}

-(void)findLocation{
[locationManager startUpdatingLocation];
[activityIndicator startAnimating];
[locationTitleField setHidden:YES];
}

-(void)foundLocation:(CLLocation *)loc{

CLLocationCoordinate2D coord = [loc coordinate];
BNRMapPoint *mp = [[BNRMapPoint alloc] initWithCoordinate:coord title:[locationTitleField text]];
NSLog(@"title field text %@", [locationTitleField text]);
[worldView addAnnotation:mp];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 250, 250);
[worldView setRegion:region animated:YES];

[locationTitleField setText:@""];
[activityIndicator stopAnimating];
[locationTitleField setHidden:NO];
[locationManager stopUpdatingLocation];

}

//CLLocationDelegate protocol methods
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{

CLLocation *location = [locations lastObject];
NSLog(@"CLLocation didUpdateLocations %@", location);

NSTimeInterval t = [[location timestamp] timeIntervalSinceNow];
if(t < -180){
    return;
}

[self foundLocation];
//NSLog(@"Latest Location: Longitude: %+.6f, Latitude: %+.6f", location.coordinate.longitude, location.coordinate.latitude);

}

-(void)locationManager:(CLLocationManager *)location didFailWithError:(NSError *)error{
NSLog(@“Could not find a location: %@”, error);
}

//MKMapViewDelegate protocol methods
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{

NSLog(@"MKMapView didUpdateUserLocation - making region around center");
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];

}

//UITextFieldDelegate protocol methods

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

NSLog(@"Finding new location");
[self findLocation];
[textField resignFirstResponder];//give up first reponder status - remove keyboard

return YES;

}

-(void)viewDidLoad{
[worldView setShowsUserLocation:YES];
}

-(void)dealloc{
[locationManager setDelegate:nil];
}

@end[/code]

[code]//BNRMapPoint.m
#import “BNRMapPoint.h”

@implementation BNRMapPoint

@synthesize coordinate, title;

-(id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t{

self = [super init];
if(self){
    coordinate = c;
    [self setTitle:title];
}

return self;

}

-(id)init{
return [self initWithCoordinate:CLLocationCoordinate2DMake(43.07, -89.3) title:@“Hometown”];
}

@end

[/code]

When i print out the text using NSLog in the foundLocation method it is correct but it is not showing up in the annotation. I also am unable to search for a city that is not in the default list in the debugger section. Would like any help or pointers. thanks!

I also get errors like this one:

[quote] <GEOTileSource: 0x8078990>: Error downloading tiles Server Error: Error Domain=GEOErrorDomain Code=-204 “The operation couldn’t be completed. (GEOErrorDomain error -204.)” UserInfo=0x163232b0 {UnderlyingErrors=(
“Error Domain=GEOErrorDomain Code=-204 “The operation couldn\U2019t be completed. (GEOErrorDomain error -204.)””
)}[/quote]

when trying to type in a new city in the text box and nothing happens. the pin on the map stays in the same place.