Google Maps SDK not showing correctly in UIView?

I'm having trouble displaying google maps in Xcode 6.1

I managed to display the map in a section of my UIView, but it displays a world map instead of a specific coordinate.

Here is the problem:

enter image description here

.h:

@interface MapViewController : UIViewController @property (strong, nonatomic) IBOutlet UIView *googleMapView; - (IBAction)mapToMain:(UIButton *)sender; @end 

.m:

 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: 32.915134 longitude: -117.140269 zoom: 17]; GMSMapView *mapView = [GMSMapView mapWithFrame:self.googleMapView.bounds camera:camera]; mapView.myLocationEnabled = YES; self.googleMapView = mapView; GMSMarker *marker = [ [GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(32.915134, -117.140269); marker.title = @"Tet Festival 2015"; marker.snippet = @"VAYA Tet"; marker.map = mapView; } 

I saw some suggestions here, but this did not work:

Can't put Google Maps GMSMapView in the subtitle of the main main view?

Using the Google Maps SDK in views other than the main view

Any suggestions?

+5
source share
3 answers

Finally it turned out ...

deleted:

 self.googleMapView = mapView; 

replace:

 [self.googleMapView addSubview:mapView]; 
+3
source

You have to add a UIView to your storyboard ... but after that you need to turn this simple UIView into a GMSMapView! Select the view you just viewed and open the Identity Inspector by selecting the third tab on the left in the Utilities toolbar, changing the name of the view class from UIView to GMSMapView, as shown in the screenshot below:

enter image description here

Your way out will not be like that

 @property (strong, nonatomic) IBOutlet UIView *googleMapView; 

it will be like this:

 @property (strong, nonatomic) IBOutlet GMSMapView *mapView; 

Your ViewDidLoad could be like this:

  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: 32.915134 longitude: -117.140269 zoom: 17]; [self.mapView animateToCameraPosition:camera]; GMSMarker *marker = [ [GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(32.915134, -117.140269); marker.title = @"Tet Festival 2015"; marker.snippet = @"VAYA Tet"; marker.map = self.mapView; 

UPDATE

Here you have an example project (enter your key)

+12
source

I am not sure what is wrong with the code above. It looks good to me. But move the camera to a specific place. You can also animate the camera.

 var newLocation = CLLocationCoordinate2DMake(latitude, longitude) googleMapView.animateToLocation(newLocation) 

Hope this works for you.

0
source

Source: https://habr.com/ru/post/1206311/


All Articles