2017-06-29 5 views
0

私はiOSでgoogle mapsを使用しています。UIView内にGoogleマップを表示

これは私のコードです:

class ViewController: UIViewController { 
    @IBOutlet weak var myMapView: GMSMapView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Create a GMSCameraPosition that tells the map to display the 
     // coordinate -33.86,151.20 at zoom level 6. 
     let camera = GMSCameraPosition.camera(withLatitude: +31.75097946, longitude: +35.23694368, zoom: 17.0) 
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 
    mapView.isMyLocationEnabled = true 
    mapView.mapType = .terrain 
    self.view = mapView 
    // Creates a marker in the center of the map. 
    let marker = GMSMarker() 
    marker.position = CLLocationCoordinate2D(latitude: +31.75097946, longitude: +35.23694368) 
    marker.title = "my location" 
    marker.map = mapView 
} 

がどのように私はマップがmyMapViewのUIViewに添付されるようになるだろうか? マーカーのタイトルが常に表示される方法はありますか?

おかげ

+0

あなたがしたいことを理解できません... – Pochi

+0

2質問。地図上のマーカーをクリックするだけでなく常に表示させる。もう一つの質問。 myMapViewというUIViewがあります。ビューはGMSMapViewのクラスです。 UIView内に表示され、UIView Controllerのビューでは直接表示されないようにしたい –

答えて

2

あなたはちょうどあなたが作成したコンセントを使用する必要があります。

class ViewController: UIViewController { 
    @IBOutlet weak var myMapView: GMSMapView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Create a GMSCameraPosition that tells the map to display the 
     // coordinate -33.86,151.20 at zoom level 6. 
     let camera = GMSCameraPosition.camera(withLatitude: +31.75097946, longitude: +35.23694368, zoom: 17.0) 
     let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 
     mapView.isMyLocationEnabled = true 
     mapView.mapType = .terrain 

     // CHANGE THIS 
     self.myMapView = mapView 

     // Creates a marker in the center of the map. 
     let marker = GMSMarker() 
     marker.position = CLLocationCoordinate2D(latitude: +31.75097946, longitude: +35.23694368) 
     marker.title = "my location" 
     marker.map = mapView 
    } 
関連する問題