cllocationdistance

CLLocation distanceFromLocation (in Swift?)

别来无恙 提交于 2019-12-04 23:19:43
问题 Can somebody please help me convert the following Objective-C statement to Swift? CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation]; I know that it must be simple to do that. I am brand new to iOS programming and any help will be greatly appreciated. Thank you! :-) 回答1: let distance = fromLocation.distanceFromLocation(toLocation) New syntax: let distance = aLocation.distance(from: anotherLocation) 回答2: func distanceFromLocation(_ location: CLLocation!) ->

calculate distance between 2 coordinates iphone - best practice

我是研究僧i 提交于 2019-12-04 20:51:25
I'm finishing an App in wish i need to show the user the distance between him and about 500 coordinates. using the CLLocation method to calculate it, works well, but it takes about 1 minute in iPhone 4 to finish calculations for each location. What is the best way to do it? Using span? Any other faster way? Thanks all, rui I think Sahgal is right, here is some code, perhaps it will help you. +(CGFloat)calculateDistanceBetweenSource:(CLLocationCoordinate2D)firstCoords andDestination:(CLLocationCoordinate2D)secondCoords { // this radius is in KM => if miles are needed it is calculated during

Find closest longitude and latitude in array from user location - iOS Swift

独自空忆成欢 提交于 2019-12-04 10:51:24
问题 In the question posted here, the user asked: I have an array full of longitudes and latitudes. I have two double variables with my users location. I'd like to test the distance between my user's locations against my array to see which location is the closest. How do I do this? This will get the distance between 2 location but stuggeling to understand how I'd test it against an array of locations. In response, he got the following code: NSArray *locations = //your array of CLLocation objects

iOS CoreLocation Altitude

坚强是说给别人听的谎言 提交于 2019-11-30 09:03:57
Prior to iOS 4.0, CoreLocation was reporting altitude correctly, now it always reports as 0 ft. -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { NSString *tLatitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]; NSString *tLongitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]; /* the following returns 0 */ NSString *tAltitude = [NSString stringWithFormat:@"%i", newLocation.altitude]; /* theres more code, but it's not relevant, and this worked prior to

iOS CoreLocation Altitude

点点圈 提交于 2019-11-29 14:02:18
问题 Prior to iOS 4.0, CoreLocation was reporting altitude correctly, now it always reports as 0 ft. -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { NSString *tLatitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]; NSString *tLongitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]; /* the following returns 0 */ NSString *tAltitude = [NSString

How to track user location in background?

那年仲夏 提交于 2019-11-28 16:44:22
I'm looking for an open source app or library to track user location in the background. Now I'm trying to do it with CLLocation and background tasks, but accuracy is not enough for my case. Could you explain, how apps, like "moves", "runkeeper", "endmondo", creates my route? Should I use Accelerometer or/and compass to create a route between CLLocation background points? Some code: //location manager init self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.distanceFilter = kCLDistanceFilterNone; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self

How to find out distance between coordinates?

非 Y 不嫁゛ 提交于 2019-11-28 16:21:03
I want to make it so that it will show the amount of distance between two CLLocation coordinates. Is there someway to do this without a complex math formula? If there isn't how would you do it with a formula? Glenn Howes CLLocation has a distanceFromLocation method so given two CLLocations: CLLocationDistance distanceInMeters = [location1 distanceFromLocation:location2]; or in Swift 4: //: Playground - noun: a place where people can play import CoreLocation let coordinate₀ = CLLocation(latitude: 5.0, longitude: 5.0) let coordinate₁ = CLLocation(latitude: 5.0, longitude: 3.0) let

How to query nearest users in Firebase with Swift?

眉间皱痕 提交于 2019-11-27 09:10:50
I want to find nearest users to my location. (For example up to 5km) My nodes in firebase database like below structure, + users + user_id0 - latitude: _ - longitude: _ Is there any way getting exact users in that radius. Otherwise I should check each user of them nearest position or not to me using CLLocation distance method. I'd highly recommend using Geofire for something like this. To set it up, your data structure will slightly change. You can still store lat/lng on your users, but you will also create a new Firebase table called something like users_locations Your users_locations table

How to query nearest users in Firebase with Swift?

只愿长相守 提交于 2019-11-26 17:48:39
问题 I want to find nearest users to my location. (For example up to 5km) My nodes in firebase database like below structure, + users + user_id0 - latitude: _ - longitude: _ Is there any way getting exact users in that radius. Otherwise I should check each user of them nearest position or not to me using CLLocation distance method. 回答1: I'd highly recommend using Geofire for something like this. To set it up, your data structure will slightly change. You can still store lat/lng on your users, but