cllocationdistance

Find nearest annotations from user location ios?

前提是你 提交于 2020-01-02 17:52:31
问题 I have an array of annotations.I am calculating the distance between each annotation from user location.What I want to know is, how can I find lets say 3 nearest annotations from these distances? Here is how I am calculating distance from user location to annotations. CLLocation *userLocation = self.mapView.userLocation.location; for (Annotation *obj in annotations) { CLLocation *loc = [[CLLocation alloc] initWithLatitude:obj.coordinate.latitude longitude:obj.coordinate.longitude]; //

Find closest longitude and latitude in array from user location

安稳与你 提交于 2020-01-02 09:59:57
问题 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. CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:userlatitude longitude:userlongitude]; CLLocation *endLocation = [[CLLocation

How to track user location in background?

孤街浪徒 提交于 2019-12-17 23:29:34
问题 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

MKMapView get distance between coordinates on customized route

青春壹個敷衍的年華 提交于 2019-12-11 20:25:17
问题 I have a custom route on map and want to get the distance between two coordinates on MKMapView . Below are the steps I have done so far... I have grabbed coordinate points and prepared an array of CLLocationCoordinate2D (like, customRoute = [CLLocationCoordinate2D] ). To show the route, using array of coordinates, I have drawn MKPolyline using MKOverlay method. And calculating the distance between two coordinates using distanceFromLocation method. When I calculate distance, the resulting

Display the distance from user with mapKit Swift (miles/km)

泪湿孤枕 提交于 2019-12-08 06:56:42
问题 I have been attempting to display the distance on a tableView but I am unable to get it to happen. This question follows up from this question: CLLocationDistance conversion. I have checked the distance. Using this function in my Location class: // Get distance func distance(to location: CLLocation) -> CLLocationDistance { return location.distance(from: self.location) } How I get the users current location: func locationManager(_ manager: CLLocationManager, didUpdateLocations locations:

Reverse function of MKCoordinateRegionMakeWithDistance?

左心房为你撑大大i 提交于 2019-12-07 17:47:09
问题 MapKit's built in function MKCoordinateRegionMakeWithDistance takes distances in meters and turns them into a MKCoordinateRegion : func MKCoordinateRegionMakeWithDistance( _ centerCoordinate: CLLocationCoordinate2D, _ latitudinalMeters: CLLocationDistance, _ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion is there a reverse function that takes a MKCoordinateRegion and gives me latitudinalMeters and longitudinalMeters? 回答1: MKCoordinateRegion gives a center (latitude and

calculate distance between 2 coordinates iphone - best practice

冷暖自知 提交于 2019-12-06 15:25:55
问题 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 回答1: I think Sahgal is right, here is some code, perhaps it will help you. +(CGFloat)calculateDistanceBetweenSource:(CLLocationCoordinate2D)firstCoords andDestination:

Find nearest annotations from user location ios?

六眼飞鱼酱① 提交于 2019-12-06 13:27:43
I have an array of annotations.I am calculating the distance between each annotation from user location.What I want to know is, how can I find lets say 3 nearest annotations from these distances? Here is how I am calculating distance from user location to annotations. CLLocation *userLocation = self.mapView.userLocation.location; for (Annotation *obj in annotations) { CLLocation *loc = [[CLLocation alloc] initWithLatitude:obj.coordinate.latitude longitude:obj.coordinate.longitude]; // CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:self.mapView.userLocation.coordinate.latitude

Find closest longitude and latitude in array from user location

不羁岁月 提交于 2019-12-06 09:11:43
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. CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:userlatitude longitude:userlongitude]; CLLocation *endLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];

Reverse function of MKCoordinateRegionMakeWithDistance?

走远了吗. 提交于 2019-12-05 18:34:21
MapKit's built in function MKCoordinateRegionMakeWithDistance takes distances in meters and turns them into a MKCoordinateRegion : func MKCoordinateRegionMakeWithDistance( _ centerCoordinate: CLLocationCoordinate2D, _ latitudinalMeters: CLLocationDistance, _ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion is there a reverse function that takes a MKCoordinateRegion and gives me latitudinalMeters and longitudinalMeters? MKCoordinateRegion gives a center (latitude and longitude) and span (delta latitude and longitude). Given these values, you can determine the location of the edges