9

我正在尝试将 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_]; 

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

此致。

4

2 回答 2

19

解决方案:

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_]; 
于 2013-10-04T14:30:02.487 回答
1

基本上在情节提要中,对于要显示 Google 地图的相应视图(UIVIew),您必须将类设置为GMSMapView身份检查器中的类。

这就是视图控制器在 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))


       }
}
于 2017-07-16T20:09:09.140 回答