0

I am trying to implement my current location within a sub view using Google Map SDK for IOS. I am trying to implement the GMSMapView as an IBOutlet.

My header file has the code

 #import <UIKit/UIKit.h>
 #import <Google-Maps-iOS-SDK/GoogleMaps/GoogleMaps.h>

 @interface TripLandingViewController : UIViewController

 @property IBOutlet GMSMapView *mapView;

 @end

My .m file has the code

    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Tile.png"]];
    self.mapView.myLocationEnabled = TRUE;



    NSLog(@"\n\n\n My Location is %f,%f \n\n\n",self.mapView.myLocation.coordinate.latitude,self.mapView.myLocation.coordinate.longitude);

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.mapView.myLocation.coordinate.latitude
                                                           longitude:self.mapView.myLocation.coordinate.longitude
                                                             zoom:10];
    self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

No matter, what hardcoded value i provide as parameters for coordinates in camera. I am getting the wrong location (here UK) which is not at all updating.

But Instead when i tried

    self.View = [GMSMapView mapWithFrame:CGRectZero camera:camera];

I was able to load correct map View in the Main View with correct location coordinates.

I tried all the answers on adding Google Map to SubViews through stackoverflow.

Cannot put a google maps GMSMapView in a subview of main main view?

How to set the frame for mapview - in google GMSMap for iOS6

How put Google MapView in UIView?

Google Maps iOS SDK, Getting Current Location of user

But nothing seems to work. Please Help since I am new to IOS Programming.

Community
  • 1
  • 1
Arjun K P
  • 2,081
  • 4
  • 20
  • 33

1 Answers1

2

Use:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:0 longitude:0 zoom:15];
 self.mapView.camera = camera;

instead of using:

self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

I'm not totally sure why, but this method works when your GMSMapView is a subview of your UIViewController.

Vivek Molkar
  • 3,910
  • 1
  • 34
  • 46
Vishay Nihalani
  • 73
  • 1
  • 1
  • 5