1
votes

I'm trying to implement current locations in my app. Please see my code for the viewDidLoad below:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self hideTabBar:self.tabBarController];

    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    mapView_.settings.compassButton = YES;
    mapView_.settings.myLocationButton = YES;
    mapView_.accessibilityElementsHidden = NO;
    self.view = mapView_;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
}

I can see the map in the iOS simulator (iPhone 4s) with the marker set to Sydney, but no blue dot to be seen anywhere. Is current location perhaps working but the UI element is hidden?

Thanks for any help/suggestions!

3
You need to have requested the permission to get the users location even to show it on the MapView.Lefteris
Sorry I'm very new to iOS. How do I request for permission? Is this a simulator setting or done programmatically?BlueBucket7
Look at the CLLocation class referenceLefteris

3 Answers

1
votes

In my app I need to implement the CLLocationManager and set NSLocationWhenInUseUsageDescriptionin the Custom Target Properties.

Hope this helps.

0
votes

In simulator, you need to set custom location like following:

Debug > Locations > Custom Location... then enter a latitude and longitude for the location you would like to simulate.

NOTE: if this method didn't work, then just select Freeway Drive instead of Custom Location. Once you clicked on Freeway Drive, then do the same step as above mentioned.

0
votes
     func didTapMyLocationButton(for mapView: GMSMapView) -> Bool {


//if want to change the camera position

            if self.latDouble != 0.0 && self.longDouble != 0.0
            {
                let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: self.latDouble, longitude: self.longDouble, zoom: 18.0)
                self.mapView.camera = camera

            }

             self.mapView.isMyLocationEnabled = true
            self.mapView.reloadInputViews()
            return true
        }