Last active
December 13, 2021 11:30
-
-
Save valeriyvan/75e4ef1787cd237fe3943d0e97b135df to your computer and use it in GitHub Desktop.
Revisions
-
valeriyvan revised this gist
Oct 7, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,8 @@ let coordinates = [(CLLocationCoordinate2D(latitude:-40.0, longitude:38.2)), // Lookup is done with one pass on array with only reduce let ((minLatitude, maxLatitude), (minLongitude, maxLongitude)) = coordinates.reduce(((DBL_MAX, DBL_MIN),(DBL_MAX, DBL_MIN))) { r, c in ( (min(c.latitude,r.0.0), max(c.latitude, r.0.1)), (min(c.longitude, r.1.0), max(c.longitude, r.1.1)) ) } -
valeriyvan created this gist
Oct 7, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ // Having array of coordinates you would like show on map you have calculate center and span for map. // For that you need min/max latitude/longitude of coordinates. let coordinates = [(CLLocationCoordinate2D(latitude:-40.0, longitude:38.2)), (CLLocationCoordinate2D(latitude:44.2, longitude:17.833)), (CLLocationCoordinate2D(latitude:5.22, longitude:154.2)), (CLLocationCoordinate2D(latitude:33.2, longitude:9.2)), (CLLocationCoordinate2D(latitude:4.2, longitude:3.2))] // Lookup is done with one pass on array with only reduce let ((minLatitude, maxLatitude), (minLongitude, maxLongitude)) = coordinates.reduce(((DBL_MAX, DBL_MIN),(DBL_MAX, DBL_MIN))) { r, c in ( (c.latitude > r.0.0 ? r.0.0 : c.latitude, c.latitude < r.0.1 ? r.0.1 : c.latitude), (c.longitude > r.1.0 ? r.1.0 : c.longitude, c.longitude < r.1.1 ? r.1.1 : c.longitude) ) } minLatitude // -40 maxLatitude // 44.2 minLongitude // 3.2 maxLongitude // 154.2