Google地图iOS SDK mylocation按钮未显示

时间:2016-04-15 16:32:09

标签: google-maps-sdk-ios

我启用了 myLocation myLocationButton , 但它没有显示在我的观点上 我尝试记录_mapView.myLocation它是nil

我需要显示 myLocation 点和 myLocationButton
有人可以帮助我,谢谢!

//
//  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];
}

1 个答案:

答案 0 :(得分:0)

我找到了显示按钮并获得用户位置

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
long lastTime = prefs.getLong("last_used");
long currentTime = System.currentTimeMillis();

//Now do the calculations as you like