- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的项目中,我每 5 秒成功获取经纬度,并且我正在保存在数据库中,但我想要每 5 秒和每 30 米距离的位置数据....
这是我在 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");
}
}
最佳答案
这里有一个可能的解决方案:
您需要为创建 NSPredicate
找到最小和最大纬度、经度值。
将度数转换为弧度
-(float)deg2rad:(float)degrees{
return degrees * M_PI / 180;
}
找到最小和最大纬度、经度值//以公里(30 米)为单位的距离值
float searchDistance = 0.03;
float minLat = userLocation.coordinate.latitude - (searchDistance / 69);
float maxLat = userLocation.coordinate.latitude + (searchDistance / 69);
float minLon = userLocation.coordinate.latitude - searchDistance / fabs(cos([self deg2rad:userLocation.coordinate.latitude])*69);
float maxLon = userLocation.coordinate.longitude + searchDistance / fabs(cos([self deg2rad:userLocation.coordinate.latitude])*69);
如下创建谓词
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"latitude <= %f AND latitude >= %f AND longitude <= %f AND longitude >= %f", maxLat, minLat, maxLon, minLon];
这将在 userLocation
周围创建一个正方形,它可能对您有帮助。
关于ios - 我想根据距离和时间获取位置经纬度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44063007/
我对纬度和经度有疑问。当我想获取坐标时,只有 24 个 API 检索坐标。其他人没有。不知道为什么 我正在使用 GPSTracker 服务 public Location getLocation()
我有一个表(DB2 数据库),其中包含城市信息和相应的经纬度以及与城市相关的许多其他信息。我的要求是: 我的应用程序的输入将是纬度和经度,它们可能是或许多不是存储在数据库中的精确纬度和经度。我需要借助
我在经度和纬度上有一个位置 (A)。 我有一条线段,起点(B)和终点(C)在经度和纬度上。 我试图计算的是从 A 到 BC 线的最短距离。 换句话说,从 A 到最近点(在 BC 线上)的距离(以米为单
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
这个问题在这里已经有了答案: Find nearest latitude/longitude with an SQL query (18 个答案) 关闭 6 年前。 我正在尝试编写一个在某个位置附近
我正在尝试将 Yelp 的 API 与纬度/经度位置结合使用。我使用了 yelp 给出的 javascript 代码,它基本上有一个参数数组,并像这样将值插入其中: parameters.push([
我有一大组纬度和经度需要存储在 MySQL 数据库中。我正在阅读有关要使用的字段类型的相互矛盾的建议。 数据的一个例子是... Lat | Long -----------------
在我的应用程序中,我通过以特定时间间隔从服务器获取他们的位置(纬度和经度)来显示其他人的位置。 获取后,我必须删除所有注释并删除基于服务器数据的新注释。 但它看起来非常低效,因为当我们以前存在相同用户
我正在尝试将鼠标在谷歌地图上的位置转换为 LatLng 对象。我看到很多关于通过谷歌地图“点击”事件等获取位置的帖子,如下所示: google.maps.event.addListener(map,
我的 SQLite 数据库中存储了经纬度数据,我想获取与我输入的参数最近的位置(例如,我当前的位置 - 纬度/经度等)。 我知道这在 MySQL 中是可能的,并且我已经进行了相当多的研究,认为 SQL
伙计们,我在我的 Android 应用程序中实现了谷歌地图,并开始创建一个标记,我在 map 中间放置了一个标记图像。现在,我希望每当用户拖动 map 时,我都能得到 map 中心的位置(我放置图像的
我正在实现 GPS 跟踪器以从 http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ 获取经度和纬度.
我有一个多边形形状文件(可下载 here ),我想从中创建一个包含 3 列的 data.frame ,其中包含: 多边形 ID 质心纬度 质心经度 来自这个答案here ,我知道以 Formal Cl
有没有办法使用facebook api以(纬度和经度格式)获取用户的位置? 我能够获得位置名称和其他属性,但不能获得该地点的经纬度。 javascript中是否有相同的API。 最佳答案 如果您有用户
在我的“原生”Android 应用程序中,我试图计算 map 上两个位置之间以英尺和/或米(如乌鸦飞翔)为单位的距离。理想情况下,会有一种方法将两个 LatLng 值(因为这是我随时可用的)作为输入并
我想使用 Google API 获取 GPS 位置。 我的代码: mGoogleApiClient = new GoogleApiClient.Builder(this)
这个问题在这里已经有了答案: How to calculate the latlng of a point a certain distance away from another? (6 个答案)
我是一名优秀的程序员,十分优秀!