gpt4 book ai didi

ios - 无法获取 Google Maps iOS SDK 的我的位置点

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:36 24 4
gpt4 key购买 nike

目前,我无法在我正在开发的应用程序中获取我的位置。

基本上,在 Google Maps iOS SDK 的文档中,Google 提到您可以:

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

但是,当我这样做时,该点不会出现在我的 View 中。

这是我的设置,我有一个包含 View 的 View Controller 。这个 View 包含三个东西,两个按钮和一个 map View :

enter image description here

我已将我的 mapView 与 GMSMapView 链接起来,我可以毫无问题地查看 map 。

现在,我想要的是定位。

我尝试了两件事。首先,使用自定义的草稿按钮(i 表示信息),我尝试手动将位置设置到 mapView,但这没有用,即使 locationServicesEnabled 方法返回 YES。

然后,我尝试使用 GoogleMaps 的点,但这也不起作用。

这是我的代码:

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's location: %@", self.mapView.myLocation);

}

我正在使用 Xcode 6.3.2 和 iOS 8.3。

最佳答案

首先检查以下东西是否存在。

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

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

如果一切都在那里,并且如果您正在模拟器上进行测试,那么请尝试从调试选项卡更改模拟器中的位置,例如将其更改为其中任何一个的免费汽车运行。

此外,检查您是否在 PLIST 中为 NSLocationWhenInUseUsageDescription 添加了描述。

关于ios - 无法获取 Google Maps iOS SDK 的我的位置点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30922291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com