/// Adds pins on map that show locations of where you swapped users
func addPins() {
for history in swapHistoryUsers{
history._latitude = "40.7128"
history._longitude = "-74.0059"
if let x_cordinate_string = history._latitude, let y_cordinate_string = history._longitude{
let x_cordinate = Double(x_cordinate_string)
let y_cordinate = Double(y_cordinate_string)
// Ensure there are cordinates presents
if let x = x_cordinate, let y = y_cordinate{
// Add Annotations
var annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(x, y)
mapView.addAnnotation(annotation)
}
}
}
}
/// Center's Map on User's Location. If there's no location, it defaults to New York City
func setupMap() {
// Gets the user's location and centers map
var currentLocation = mapView.userLocation.coordinate
if currentLocation.latitude == 0 && currentLocation.longitude == 0 {
// Set Location to default location
let NewYorkCity = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0059)
currentLocation = NewYorkCity
}
let region = MKCoordinateRegion(center: currentLocation, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
mapView.setRegion(region, animated: true)
}