使用Google Maps SDK的方法,比如MapKit的struct MKCoordinateRegion

Which to use method of Google Maps SDK like struct MKCoordinateRegion of MapKit

我为 iOS 的 Google Maps SDK 修改了 this tutorial。我想通过提供一个中心点和一个定义水平和垂直范围的跨度来定义它。 我读了 this tutorial of Google Maps SDK for iOS 我认为应该使用 zoomAtCoordinate:forMeters:perPoints: 这不太对,在我看来

    func mapRegion() -> MKCoordinateRegion {
        var region: MKCoordinateRegion = MKCoordinateRegion(center: CLLocationCoordinate2DMake(0, 0), span: MKCoordinateSpanMake(0, 0))
        var initialLoc: Location = self.trek.locations.firstObject as! Location
var minLat = (initialLoc as Location).latitude.doubleValue
        var minLng = (initialLoc as Location).longitude.doubleValue
        var maxLat = (initialLoc as Location).latitude.doubleValue
        var maxLng = (initialLoc as Location).longitude.doubleValue

        for location in self.trek.locations.array {
            if (location as! Location).latitude.doubleValue < minLat {
                minLat = (location as! Location).latitude.doubleValue;
            }
            if (location as! Location).longitude.doubleValue < minLng {
                minLng = (location as! Location).longitude.doubleValue;
            }
            if (location as! Location).latitude.doubleValue > maxLat {
                maxLat = (location as! Location).latitude.doubleValue;
            }
            if (location as! Location).longitude.doubleValue > maxLng {
                maxLng = (location as! Location).longitude.doubleValue;
            }
        }

        region.center.latitude = (minLat + maxLat) / 2.0;
        region.center.longitude = (minLng + maxLng) / 2.0;

        region.span.latitudeDelta = (maxLat - minLat) * 1.1; // 10% padding
        region.span.longitudeDelta = (maxLng - minLng) * 1.1; // 10% padding

        return region;

    }

你必须使用GMSCoordinateBounds

func mapRegion() -> GMSCoordinateBounds {
        var path = GMSMutablePath()
        var bounds = GMSCoordinateBounds(path: path)
        var initialLoc: Location = self.trek.locations.firstObject as! Location    
        var minLat = (initialLoc as Location).latitude.doubleValue
        var minLng = (initialLoc as Location).longitude.doubleValue
        var maxLat = (initialLoc as Location).latitude.doubleValue
        var maxLng = (initialLoc as Location).longitude.doubleValue      
        for location in self.trek.locations.array {
            if (location as! Location).latitude.doubleValue < minLat {
                minLat = (location as! Location).latitude.doubleValue;
            }
            if (location as! Location).longitude.doubleValue < minLng {
                minLng = (location as! Location).longitude.doubleValue;
            }
            if (location as! Location).latitude.doubleValue > maxLat {
                maxLat = (location as! Location).latitude.doubleValue;
            }
            if (location as! Location).longitude.doubleValue > maxLng {
                maxLng = (location as! Location).longitude.doubleValue;
            }
        }       
        path.addCoordinate(CLLocationCoordinate2DMake(minLat, minLng))
        path.addCoordinate(CLLocationCoordinate2DMake(maxLat, maxLng)) 
        return bounds;
    }   
self.viewMap?.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(mapRegion(), withPadding: 15.0))