Having some trouble trying to figure out the best way to go about this.
I have a tableView populated with custom cells that display events that are occurring. I can display the address for each of the venues and would like to display the distance from the users' current location to the venue address, in miles, in a label on an given UITableViewCell.
Not really sure on the best way to go about this, any guidance would be appreciated.
Here's what I've done so far:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let lastLocation = locations.last
let chester = CLLocation(latitude: 53.19, longitude: -2.89)
let venueLoc = CLGeocoder();
CLGeocoder().geocodeAddressString(post.venueAddress!) { (placemarks, error) in
if error == nil {
let placemark = placemarks![0] as CLPlacemark
}
}
let distanceInMeters = lastLocation?.distanceFromLocation(chester)
let distanceInMiles = distanceInMeters! / 1609.34
distanceFromLoc.text = "\(String(format: "%.1f", distanceInMiles)) mi"
You can see that I've been able to assign the correct string to my label but I am using given coordinates (chester), I cannot figure out how to take the geocodeAdressString function and use it correctly with the distance in meters line.
Any help would be appreciated.