I have two questions. (First) I’m trying to make it where whenever the iPhone moves in location at all, an alert box pops up and shows the longitude where they were, and the latitude where they are now. This is for testing purposes for part of a bigger project I’m working on. Problem is, no alert box is popping up at all. I thought that when the location manager gets a new location, it fires up the delegate which should show the location in an alert box, however nothing is happening at all.
Here is how I’m setting up the Location Manager:
- (void)viewDidLoad
{
locationManager =[[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
}
Here is the delegate:
-(void) locationmanager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation
{
float oldlat;
float oldlng;
float lat;
float lng;
NSDate *oldtime;
NSDate *newtime;
lat = newLocation.coordinate.latitude;
lng = newLocation.coordinate.longitude;
newtime = newLocation.timestamp;
oldlat = oldLocation.coordinate.latitude;
oldlng = oldLocation.coordinate.longitude;
oldtime = oldLocation.timestamp;
NSNumber *oldlong = [NSNumber numberWithFloat:oldlng];
NSNumber *newlat = [NSNumber numberWithFloat:lat];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:oldlong
message:newlat
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Submit",nil];
[alert show];
(Secondly) once I’m satisfied that I’m able to track the new and old latlng, does anybody know the best way to store the data? I have researched sqlite, core data, and just using arrays, but i’m still having doubts as to whats the best way to store the lat, lng, timestamp and username that will be generated probably a couple hundred times a day for around 200 users, and then send it to a server.
I know this was a long question, but any insight at all would be greatly appreciated!
Ok. I am really astonished why your application did not crash at this line:
If try to understand
UIAlertViewparameters properly you will seeinitWithTitleandmessageparameters are of typeNSStringand what you are passing isNSNumberso take twoNSStringfor lattitude and longitude and pass them as a parameter like this.But showing alert in
didUpdateToLocationwon’t be a good idea as it will constantly gets called so you will have alert pop up each second locking up your interaction. Though this code worked for me. Have a look at screenshot.