Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

xcode - How to put Google Map in a custom UIView

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 maps in a different UIView from the principal one in order to be able to show my menu bar on top.

Here is my actual code :

#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@implementation MapViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:46.809885
                                                            longitude:-71.184556
                                                                 zoom:18];
    mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    self.view = mapView;
    mapView.mapType = kGMSTypeHybrid;

}

@end

Actually, the map is all over the app. It already set the class of my UIView to GMSKMapView and made an outlet name mapView to link my UIView with the controller.

I use Xcode 4.6.2

Thank you for your help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

<GMSMapViewDelegate>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...