How to put Google Map in a custom UIView

后端 未结 2 1951
无人及你
无人及你 2020-12-20 02:17

I know this question has already been asked before, but none of the answers were really clear to me and I can\'t find good tutorial on Internet... So, I want to put Google m

2条回答
  •  攒了一身酷
    2020-12-20 03:12

    I'm using this code:

    //header file

    @property (strong, nonatomic) IBOutlet UIView *viewForMap;
    @property (nonatomic, strong) IBOutlet GMSMapView *mapView;
    @property (nonatomic, strong) IBOutlet GMSCameraPosition *camera;
    

    //implementation file

     self.camera = [GMSCameraPosition cameraWithLatitude:46.2220
                                              longitude:25.2330 zoom:5
                                                bearing:0
                                           viewingAngle:0
                   ];
    
        self.mapView = [GMSMapView mapWithFrame:_viewForMap.bounds camera:_camera];
        self.mapView.delegate = self;
    
        [self.viewForMap addSubview:_mapView];
    

    UPD

    to change map type:

    self.mapView.mapType = kGMSTypeHybrid; //kGMSTypeNormal kGMSTypeHybrid kGMSTypeSatellite kGMSTypeTerrain
    

    to change again camera view:

    _mapView.camera = [GMSCameraPosition cameraWithLatitude:newLat
                                                      longitude:newLong
                                                           zoom:1
                                                        bearing:0
                                                   viewingAngle:0
                           ];
    

    don't forget to add in header file:

    
    

提交回复
热议问题