无法获取Google Maps iOS SDK的位置点(Cannot get the my location dot for Google Maps iOS SDK)

编程入门 行业动态 更新时间:2024-10-28 11:22:19
无法获取Google Maps iOS SDK的位置点(Cannot get the my location dot for Google Maps iOS SDK)

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

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

通过在GMSMapView上设置myLocationEnabled启用蓝色“我的位置”点和指南针方向https://developers.google.com/maps/documentation/ios/map#my_location

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

这是我的设置,我有一个包含视图的视图控制器。 此视图包含三个内容,两个按钮和一个地图视图:

我已将mapView与GMSMapView相关联,我可以毫无问题地查看地图。

现在,我想要的是找到它。

我尝试了两件事。 首先,使用自定义草稿按钮(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。

Currently, I am not able to get my location in the app I am developing.

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

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

However, when I do that, 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:

I have linked my mapView with GMSMapView and I can see the map without any problems.

Now, what I would want, is to be located.

I tried two things. First, using a custom, draft button (the i for information), I tried to manually set the location to the mapView but this wasn't working even though the locationServicesEnabled method returned YES.

Then, I tried using GoogleMaps's dot but this isn't working 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's location: %@", self.mapView.myLocation); }

I am using Xcode 6.3.2 and 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;

如果Everything在那里,如果你在模拟器上进行测试,那么尝试从调试选项卡中更改模拟器中的位置,例如将其更改为任何一个的自由车运行。

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

First check out following things are there or not.

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 Simulator then try to change the location in Simulator from debug Tab, e.g. change It to Free car run of any of them.

Also, check if you have added Description in PLIST for NSLocationWhenInUseUsageDescription.

更多推荐

本文发布于:2023-07-05 08:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1035430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   iOS   Google   Maps   dot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!