2013-10-04 16 views
8

我正在尝试将Google MapView放入UIView,但没有显示任何内容。如何把Google MapView放在UIView中?

我的代码,

的* .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_; 

感谢。

解决方案

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_]; 

所以,我得到了解决。不管怎么说,还是要谢谢你。

此致敬礼。

+1

后,作为回答,然后接受,这将是很有益的 – Vinodh

回答

17

解决方案:

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

你是绝对正确的,非常感谢你 – IKKA

0

本质的故事板,为对应的视图(UIView的)你要显示的谷歌地图,你必须设置类中的身份检查GMSMapView

这是视图控制器会怎么看起来像雨燕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)) 


     } 
}