How to install Google MapView in UIView?

I am trying to put a Google MapView in a UIView , but I can’t see anything.

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

Thanks.

Decision

 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, I got a solution. Anyway, thanks.

Sincerely.

+8
ios uiview google-maps-sdk-ios
source share
2 answers

Decision:

 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_]; 
+17
source share

Essentially in the storyboard, for the corresponding view (UIVIew) you are going to show the Google map, you must set the class as GMSMapView in the identity inspector.

Here's what the view controller will look like 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)) } } 
0
source share

All Articles