2013-10-04 5 views
8

Ich versuche Google MapView in UIView zu setzen, aber ich bekomme nichts angezeigt.Wie Google MapView in UIView?

Mein Code,

* .h

#import <UIKit/UIKit.h> 
#import <GoogleMaps/GoogleMaps.h> 

@interface ViewController : UIViewController 

@property (weak, nonatomic) IBOutlet UIBarButtonItem *btnLocate; 
@property (weak, nonatomic) IBOutlet GMSMapView *mapView_; 
@property (weak, nonatomic) IBOutlet UIView *mapView; 

@end 

* .m

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 
    self.mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    self.mapView_.myLocationEnabled = YES; 
    self.mapView = self.mapView_; 

Dank.

Lösung

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 

    // Indicating the map frame bounds 
    self.mapView_ = [GMSMapView mapWithFrame:self.mapView.bounds camera: camera]; 
    self.mapView_.myLocationEnabled = YES; 

    // Add as subview the mapview 
    [self.mapView addSubview: self.mapView_]; 

So bekam ich die Lösung. Danke trotzdem.

Mit freundlichen Grüßen.

+1

Beitrag aussehen würde, dass als Antwort dann akzeptieren, die wirklich hilfreich sein – Vinodh

Antwort

17

Lösung:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 

    // Indicating the map frame bounds 
    self.mapView_ = [GMSMapView mapWithFrame:self.mapView.bounds camera: camera]; 
    self.mapView_.myLocationEnabled = YES; 

    // Add as subview the mapview 
    [self.mapView addSubview: self.mapView_]; 
+0

Sie absolut richtig sind, vielen Dank – IKKA

0

Wesentlichen im Storyboard, für die entsprechende Ansicht (UIView) können Sie die Google Map zeigen gehen, haben Sie die Klasse als GMSMapView in Identität Inspektor zu setzen.

Dies ist, wie View-Controller wie in Swift 3.

class GMapsViewController: UIViewController { 
    @IBOutlet weak var mapContainerView: GMSMapView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0) 

     let marker = GMSMarker() 
     marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20) 
     marker.title = "Sydney" 
     marker.map = mapContainerView 

     mapContainerView.moveCamera(GMSCameraUpdate.setCamera(camera)) 


     } 
}