Question

I Use Google Map iOS SDK in my app but I have this issue :

When I used google example for iOS like the following code it work fine but it will loaded in full screen mode because it take the main view in the ViewController.

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                        longitude:151.2086
                                                             zoom:6];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

GMSMarker *marker = [[GMSMarker alloc] init];

marker.position = camera.target;
marker.snippet = @"Hello World";
marker.map = mapView;
self.view = mapView;

But I need it to be in subView , u know because toolbar or top bar whatever .

I add subView to myViewController and make an IBOUtle then I link the mapView to it like this :

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                        longitude:151.2086
                                                             zoom:6];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

GMSMarker *marker = [[GMSMarker alloc] init];

marker.position = camera.target;
marker.snippet = @"Hello World";
marker.map = mapView;
mySubView = mapView;

but the View will be white/empty no map loaded/or add as subView, so I tried the following , change the subView type from UIView to GMSMapView and this make the map appear and loaded.

The strange problem that I can't do anything with this Map like the GMSMarker does not appear , or GMSCameraPosition does not show your the correct position/not work.

Was it helpful?

Solution

if your outlet is a UIView and you make the map in code, you have to add it.

Obj-C:

mapView.frame = mySubview.bounds;
[mySubview addSubview:mapView];

Swift:

mapView.frame = mySubview.bounds;
mySubview.addSubview(mapView)

if your OUTLET is a mapview then use that and dont make a new one

mapView = (GMSMapView*)mySubView;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top