Help ...no red annotation pin or location name


#1

Hi

I seem to be stuck with a problem when I run the whereami app on my ipod touch(4th gen) and hope someone can help.

When I run the app the map shows and the blue dot showing the current location.

When I enter a name for the current location and press done on the keyboard, the keyboard and textfield disappear ok, but no red annotation pin, or my new location name appear…the blue dot remains with the activity monitor spinning.

As far as I can tell my code is correct and also my connections in the xib file.

Interestingly, when I comment out this code like below …

 //NSTimeInterval t =[[newLocation timestamp]timeIntervalSinceNow];

//CLLocationManagers will return the last found location of the device first
//you dont 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 dont want it, keep looking
// return;

…the red annotation pin does appear, but still the name I’ve typed in doesn’t.

Hope I’ve explained tis ok and would appreciate any help.

Thanks

Len

here is my implementation code…

#import “WhereamiAppDelegate.h”
#import “MapPoint.h”

@implementation WhereamiAppDelegate

@synthesize window = _window;

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

-(void)foundLocation:(CLLocation *)loc
{
CLLocationCoordinate2D coord =[loc coordinate];

//create an instance of mapoint with the current data
MapPoint *mp =[[MapPoint alloc]initWithCoordinate:coord title:[locationTitleField text]];

//add it to the mapview
[worldView addAnnotation:mp];

//mkmapview retains its annotations so we can release
[mp release];

//zoom the region to this location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 250, 250);
[worldView setRegion:region animated:YES];

[locationTitleField setText:@""];


[activityIndicator stopAnimating];
[locationTitleField setHidden:NO];
[locationManager stopUpdatingLocation];    

}

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

    //create a location Manager object
    locationManager = [[CLLocationManager alloc]init];

    [locationManager setDelegate:self];

    //we want all results from the location manager
    [locationManager setDistanceFilter:kCLDistanceFilterNone];

    //and we want it to be as accurate as possible regardless of how much
    //time/power it takes
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

    //tell our manager to start looking for its location immeadiatley
    //[locationManager startUpdatingLocation];
    [worldView setShowsUserLocation:YES];

    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];
    return YES;
    }

-(BOOL)textFieldShouldReturn:(UITextField *)tf
{
//this method isnt implemented yetbut will be soon
[self findLocation];

[tf resignFirstResponder];

return  YES;

}

  • (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)u
    {
    CLLocationCoordinate2D loc = [u coordinate];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
    [worldView setRegion:region animated:YES];
    }

-(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 dont 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 dont want it, keep looking
    return;
[self foundLocation:newLocation];

}

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

  • (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager
    {
    NSLog(@"%@",[locationManager heading]);
    return YES;
    }
    */

  • (void)applicationWillResignActive:(UIApplication )application
    {
    /

    Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    */
    }

  • (void)applicationDidEnterBackground:(UIApplication )application
    {
    /

    Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    */
    }

  • (void)applicationWillEnterForeground:(UIApplication )application
    {
    /

    Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    */
    }

  • (void)applicationDidBecomeActive:(UIApplication )application
    {
    /

    Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    */
    }

  • (void)applicationWillTerminate:(UIApplication )application
    {
    /

    Called when the application is about to terminate.
    Save data if appropriate.
    See also applicationDidEnterBackground:.
    */
    }

  • (void)dealloc
    {
    [_window release];
    [super dealloc];
    }

@end


#2

Hi,

You have:

if(t<180) when it should be  if (t < -180)

HTH
Gareth


#3

Cheers Gareth

Well spotted ! :slight_smile:

Works perfect now,

Thanks

Len

p.s if anyones just trying this exercise at home on a wifi network i dropped the distance down to 2 metres in the

  • (void)mapView: didUpdateUserLocation: method

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 2, 2);

so you can create diff locations around house


#4

Hello there -

I’m experiencing the same problem. When I run the app, it updates the blue dot to my current location and zooms. When I enter a name and press done, the textfield disappears, the activity indicator is animated, but no red pin ever appears.

In my case, didUpdateToLocation:fromLocation: is never getting called. Any ideas?