Can't get my location point for Google Maps iOS SDK

I am currently unable to get my location in an application I am developing.

Basically, in the documentation for the Google Maps iOS SDK, Google mentions that you can:

enable the blue point "My location" and compass direction by setting myLocationEnabled in GMSMapView https://developers.google.com/maps/documentation/ios/map#my_location

However, when I do this, the dot does not appear in my view.

Here's my setup, I have a view controller that contains a view. This view contains three things, two buttons and a map view:

enter image description here

I have linked my mapView to the GMSMapView and I can see the map with no problem.

Now what I want should be located.

I've tried two things. First, using a custom draft button (i for info), I tried to manually set the location in the mapView, but it didn't work, although the locationServicesEnabled method returned YES.

Then I tried using googlemaps hotspot but that doesn't work either.

Here's my code:

StudyDisplayViewController.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "GoogleMaps/GoogleMaps.h"


@interface StudyDisplayViewController : UIViewController <CLLocationManagerDelegate> {

}

@property (strong, readwrite) CLLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet GMSMapView *mapView;

@end

      

StudyDisplayViewController.m

#import "StudyDisplayViewController.h"

@interface StudyDisplayViewController ()
- (IBAction)closeStudyDisplay:(id)sender;
- (IBAction)locateMe:(id)sender;

@end

@implementation StudyDisplayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
        NSLog(@"Starting the location service");
        [self.locationManager requestWhenInUseAuthorization];
        [self.locationManager startMonitoringSignificantLocationChanges];
        if([CLLocationManager locationServicesEnabled]) {
            NSLog(@"all good");
        }
        else {
            NSLog(@"Damn son");
        }
    }

    self.mapView.settings.compassButton = YES;       

    self.mapView.myLocationEnabled = YES;    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

}

-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    NSLog(@"Getting Location");
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)closeStudyDisplay:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)locateMe:(id)sender {

    NSLog(@"User location: %@", self.mapView.myLocation);

}

      

I am using Xcode 6.3.2 and iOS 8.3.

+3


source to share


1 answer


First check if there is something like that.

    locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate= self;
    if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
        [locationManager requestWhenInUseAuthorization];
    }
    [locationManager startUpdatingLocation];

    _mapView.myLocationEnabled =  YES;
    _mapView.settings.myLocationButton =  YES;

      



If everything is there, and if you are testing on the Simulator, try changing the location in the Simulator from the debug tab for example. change it to free run of any of them.

Also, check if the PLIST has a PLIST description for NSLocationWhenInUseUsageDescription

.

+4


source







All Articles