Dans mon projet, je reçois la latitude et la longitude avec succès pour chaque 5sec, et je fais des économies dans la base de données, mais je veux des données d'emplacement pour toutes les 5 s et toute distance de 30 mètres ....Je souhaite connaître la latitude et la longitude de l'emplacement en fonction de la distance et de l'heure?
Ceci est mon code dans viewController .m
//When I click button this method called...
- (IBAction)getLocationDetails:(UIButton *)sender {
[self CurrentLocationIdentifier];
timer = [NSTimer scheduledTimerWithTimeInterval:5.0f
target:self
selector:@selector(CurrentLocationIdentifier)
userInfo:nil
repeats:YES];
}
-(void)CurrentLocationIdentifier {
//---- For getting current gps location
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
currentLocation = [locations objectAtIndex:0];
self.longitudeString = @(currentLocation.coordinate.longitude).stringValue;
self.latitudeString = @(currentLocation.coordinate.latitude).stringValue;
[locationManager stopUpdatingLocation];
manager.delegate = nil;
NSLog(@"New longitude %@", self.longitudeString);
NSLog(@"New latitude %@", self.latitudeString);
dispatch_async(dispatch_get_main_queue(), ^{
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error)
{
NSString *CountryArea;
if (!(error))
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"\nCurrent Location Detected.......\n");
// NSLog(@"placemark : %@",placemark);
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
NSString *address = [[NSString alloc]initWithString:locatedAt];
NSLog(@"Address : %@", address);
self.addressString = [[NSString alloc]initWithString:address];
[self saveData];
}
else
{
NSLog(@"Geocode failed with error %@", error);
NSLog(@"\nCurrent Location Not Detected\n");
//return;
CountryArea = NULL;
}
}];
});
// Here is the distance calculation...
CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];
CLLocation *endLocation = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];
CLLocationDistance distance = [startLocation distanceFromLocation:endLocation];
if (distance == 0) {
NSLog(@"Distance.... %f", distance);
}
}
- (void)saveData {
NSManagedObject * managedObj = [[NSManagedObject alloc]initWithEntity:self.GPSDatabaseED insertIntoManagedObjectContext:self.ad.managedObjectContext];
[managedObj setValue:self.longitudeString forKey:@"longitude"];
[managedObj setValue:self.latitudeString forKey:@"latitude"];
[managedObj setValue:self.addressString forKey:@"address"];
[managedObj setValue:self.UDIDString forKey:@"udid"];
NSError * errorObj;
[self.ad.managedObjectContext save:&errorObj];
if (errorObj) {
NSLog(@"Something goes wrong");
}else
{
NSLog(@"Saved Successfully");
}
}
Cela indique une erreur Attendant ')' – Marking
mettre à jour la réponse, vérifiez maintenant – Lalji
Vous avez une erreur de calcul pour minLon et maxLon. il ne doit pas utiliser la latitude, seulement la longitude: float minLon = userLocation.coordinate. longitude - searchDistance/fabs (cos ([auto-deg2rad: userLocation.coordinate.longitude]) * 69); float maxLon = userLocation.coordinate.longitude + rechercheDistance/fabs (cos ([self deg2rad: userLocation.coordinate.longitude]) * 69); – Andrey