2017-10-06 29 views
0

새로운 코더는 내보기에 Google지도를 맞추려고합니다.신속 GoogleMaps fitBounds 확대

많은 정보를 검색했으며이 결론에 도달했지만 저에게는 효과가 없습니다.

재정의 FUNC의에는 loadView() {

var markerList = [GMSMarker]() 

    // Create a GMSCameraPosition 
    let camera = GMSCameraPosition.camera(withLatitude: 4.390205, longitude: 2.154007, zoom: 8) 
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 
    mapView.isMyLocationEnabled = true 
    view = mapView 

    mapView.settings.myLocationButton = true 
    //mapView.setMinZoom(10, maxZoom: 20) 

    //create markers 
    for loc in arrayOfMapStops { 
     let marker = GMSMarker() 
     marker.position = CLLocationCoordinate2D(latitude: loc.lat, longitude: loc.long) 
     marker.title = loc.address 
     marker.snippet = loc.type 
     if loc.type == "Entrega" {marker.icon = GMSMarker.markerImage(with: .green)} 
     else {marker.icon = GMSMarker.markerImage(with: .blue)} 
     marker.map = mapView 
     markerList.append(marker) 
    } 

    //fit map to markers 
    var bounds = GMSCoordinateBounds() 
    for marker in markerList { 
     bounds = bounds.includingCoordinate(marker.position) 
    } 
    let update = GMSCameraUpdate.fit(bounds) 
    mapView.moveCamera(update) 
} 

지도는 적절한 줌 조정되지 않습니다.

image of situation

사람은 줌 문제를 도와 줄 수 있습니까? 사전 :

+0

감사 :

여기 내 마지막 코드입니다! –

답변

0

에서

덕분에 나 자신에 의해 문제를 해결했다. DispatchQueue를 사용하여 내지도를 오른쪽으로 확대/축소합니다. @Nrzonline을 제안하기위한

override func loadView() { 

    var markerList = [GMSMarker]() 

    // Create a GMSCameraPosition 
    let camera = GMSCameraPosition.camera(withLatitude: 40.4167 , longitude: -3.70325, zoom: 8) 
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 
    mapView.isMyLocationEnabled = true 
    view = mapView 

    mapView.settings.myLocationButton = true 
    //mapView.setMinZoom(10, maxZoom: 20) 

    //create markers 
    for loc in arrayOfMapStops { 
     let marker = GMSMarker() 
     marker.position = CLLocationCoordinate2D(latitude: loc.lat, longitude: loc.long) 
     marker.title = loc.address 
     marker.snippet = loc.type 
     if loc.type == "Entrega" {marker.icon = GMSMarker.markerImage(with: .green)} 
     else {marker.icon = GMSMarker.markerImage(with: .blue)} 
     marker.map = mapView 
     markerList.append(marker) 
    } 

    delay(seconds: 3) {() ->() in 
     //fit map to markers 
     var bounds = GMSCoordinateBounds() 
     for marker in markerList { 
      bounds = bounds.includingCoordinate(marker.position) 
     } 
     let update = GMSCameraUpdate.fit(bounds, withPadding: 100.0) 
     mapView.animate(with: update) 
    } 
} 

func delay(seconds: Double, completion:@escaping()->()) { 
    let when = DispatchTime.now() + seconds 
    DispatchQueue.main.asyncAfter(deadline: when) { 
     completion() 
    } 
} 

: