I am a complete newbi to objective c and iphone sdk and learning some great stuff with new obstacles
ok my problem is i am trying to create a browser app which shows the current location as its html content but i am not getting the location
I was able to get the browser app working from this simple and great
tutorial
now i am modifying the code so the html code displays the latitude and longitude
my app is showing 0.0000 for both latitude and longitude i dont know why i am not getting any current location
myGPSBrowser.m
Code:
#import "myGPSBrowserAppDelegate.h"
@implementation myGPSBrowserAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// initializing the location manager
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
// locationManager.distanceFilter = 1000; // 1 kilometer
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
NSDate* eventDate = locationManager.location.timestamp;
NSTimeInterval howRecent;
// if the location as nt got in last 5 sec then keep trying to get the location
do{
howRecent = [eventDate timeIntervalSinceNow];
}
while(abs(howRecent) > 5.0);
//stop the location manager
[locationManager stopUpdatingLocation];
//get the latitude and longitude
float mylat= locationManager.location.coordinate.latitude+0.0;
float mylon= locationManager.location.coordinate.latitude+0.0;
//create the html for the browser
NSString *HTMLData = [NSString stringWithFormat: @"latitude - %f longitude - %f at %f",mylat, mylon, howRecent];
[webView loadHTMLString:HTMLData baseURL:nil];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
and here is my myGPSBrowser.h
Code:
#import <UIKit/UIKit.h>
@interface myGPSBrowserAppDelegate : NSObject <UIApplicationDelegate, CLLocationManagerDelegate>{
UIWindow *window;
IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
//@property(assign, nonatomic) id<CLLocationManagerDelegate> delegate
@end
/*@interface MyLocationGetter : UIViewController<CLLocationManagerDelegate>
{
// NSString *str;
}
//@property (nonatomic, retain) NSString *str;
//@property (nonatomic, retain) NSString *locationManager;
@end */
it looks very simple and should work i dont know why it is not working