2016-04-15 12 views
0

I aktiviert MyLocation und myLocationButton, aber auf meiner Ansicht nicht angezeigt.
Und ich versuche log _mapView.myLocation es ist nil.Google Maps iOS SDK mylocation Schaltfläche nicht angezeigt

Ich brauche MyLocation Punkt und myLocationButton zu zeigen.
Kann mir jemand helfen, danke!

// 
// ViewController.m 
// 

#import "ViewController.h" 
#import <CoreLocation/CoreLocation.h> 
#import <GoogleMaps/GoogleMaps.h> 
#import "Reachability.h" 

@interface ViewController()<GMSMapViewDelegate,CLLocationManagerDelegate> 
{ 
    CLLocationManager * locationManager; 
    CLLocation *currentLocations; 
    Reachability * udnReach; 
}; 

@property (strong,nonatomic) GMSMapView * mapView; 
@property (strong,nonatomic) NSDictionary * dic; 
@property (nonatomic,strong) NSTimer * updatetimer; 


@end 

@implementation ViewController { 
} 

- (void)viewDidLoad { 
    locationManager =[[CLLocationManager alloc]init]; 
    locationManager.delegate =self; 
    if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { 
     [locationManager requestAlwaysAuthorization]; 
    } 

    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.activityType = CLActivityTypeAutomotiveNavigation; 
    [locationManager startUpdatingLocation]; 

    _mapView.delegate = self; 
    _mapView.myLocationEnabled = YES; 
    _mapView.settings.myLocationButton = YES; 
    //Map 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude 
                  longitude:locationManager.location.coordinate.longitude 
                   zoom:16]; 
    _mapView= [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(networkStatusChanged:) name:kReachabilityChangedNotification object:nil]; 
    udnReach=[Reachability reachabilityWithHostName:@"google.com"]; 
    // udnReach = [Reachability reachabilityForInternetConnection]; 
    [udnReach startNotifier]; 

    [self updatebike]; 
    self.view = self.mapView; 
    NSLog(@"User's location: %@", _mapView.myLocation); 
// Do any additional setup after loading the view, typically from a nib. 
    [super viewDidLoad]; 
} 

Antwort

0

i finden Schaltfläche zeigen und userlocation

// Rather than setting -myLocationEnabled to YES directly, 
// call this method: 

- (void)enableMyLocation 
{ 
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; 

    if (status == kCLAuthorizationStatusNotDetermined) 
     [self requestLocationAuthorization]; 
    else if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted) 
     return; // we weren't allowed to show the user's location so don't enable 
    else 
     [self.view setMyLocationEnabled:YES]; 
} 

// Ask the CLLocationManager for location authorization, 
// and be sure to retain the manager somewhere on the class 

- (void)requestLocationAuthorization 
{ 
    _locationAuthorizationManager = [[CLLocationManager alloc] init]; 
    _locationAuthorizationManager.delegate = self; 

    [_locationAuthorizationManager requestAlwaysAuthorization]; 
} 

// Handle the authorization callback. This is usually 
// called on a background thread so go back to main. 

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 
{ 
    if (status != kCLAuthorizationStatusNotDetermined) { 
     [self performSelectorOnMainThread:@selector(enableMyLocation) withObject:nil waitUntilDone:[NSThread isMainThread]]; 

     _locationAuthorizationManager.delegate = nil; 
     _locationAuthorizationManager = nil; 
    } 
} 
erhalten