"My location button" 在 google 地图中消失了

"My location button" in google map disappeared

我正在尝试向 google 地图添加一个视图,这两个视图都是使用故事板创建的。为此,我更改了这部分代码:

    mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

对此:

  mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
  self.mapView.myLocationEnabled = YES;
 [self.view insertSubview:mapView atIndex:0];

它可以工作,但默认的 "My location button" 在此之后消失了。有没有办法找回默认按钮?我将不胜感激任何帮助。

我试过这个解决方案My location button not appearing in view (Google maps SDK, ios) 但它没有用,或者我没有理解正确,如果这是唯一的解决方案,你能详细解释一下吗?

您是否正确请求访问定位服务? iOS 8. 尝试将以下内容添加到您的 Info.plist 文件中,如果有效请告诉我:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message to request location usage permission goes here</string>

我通过从情节提要中创建一个按钮并将其连接到此操作来解决这个问题。

- (IBAction)MyLocation:(id)sender {

CLLocation *location = mapView.myLocation;
if (location) {
    [mapView animateToLocation:location.coordinate];
}  }

在我的例子中,如果我将创建的按钮放在下 right/left 角仍然无法获得它,但其他地方都很好。 (我不知道为什么我会这样想,因为在索引 0 或类似位置插入地图)。