Google Maps SDK not displaying properly in UIView?

前端 未结 3 625
南旧
南旧 2020-12-11 06:37

I\'m having some problems displaying google maps in Xcode 6.1

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

相关标签:
3条回答
  • 2020-12-11 07:09

    You have to add a UIView to your Storyboard... but after that you have to turn this simple UIView into a GMSMapView! Select the view you just added and open the Identity Inspector by selecting the third tab from the left in the Utilities toolbar, change the view’s class name from UIView to GMSMapView, as shown in the screenshot below:

    enter image description here

    Your Outlet will not be like this

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

    it will be like this

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

    Your ViewDidLoad can 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 (insert your Key)

    0 讨论(0)
  • 2020-12-11 07:13

    I am not sure what is wrong with the code above. It looks fine for me. But to move the camera to certain location. You can animate the camera there as well.

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

    Hope that it works for you.

    0 讨论(0)
  • 2020-12-11 07:24

    Finally figured it out...

    removed:

    self.googleMapView = mapView;
    

    replaced:

    [self.googleMapView addSubview:mapView];
    
    0 讨论(0)
提交回复
热议问题