【问题标题】:Blue dot for current location not displaying using google maps for iOS当前位置的蓝点未使用 iOS 版谷歌地图显示
【发布时间】:2014-10-19 00:10:24
【问题描述】:

我正在尝试在我的应用中实现当前位置。请在下面查看我的viewDidLoad 代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self hideTabBar:self.tabBarController];

    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    mapView_.settings.compassButton = YES;
    mapView_.settings.myLocationButton = YES;
    mapView_.accessibilityElementsHidden = NO;
    self.view = mapView_;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
}

我可以在 iOS 模拟器 (iPhone 4s) 中看到标记设置为悉尼的地图,但在任何地方都看不到蓝点。当前位置是否有效但 UI 元素被隐藏?

感谢您的任何帮助/建议!

【问题讨论】:

  • 您需要请求获得用户位置的权限才能在 MapView 上显示它。
  • 抱歉,我是 iOS 新手。我如何请求许可?这是模拟器设置还是以编程方式完成?
  • 查看CLLocation类参考

标签: ios objective-c iphone google-maps xcode6


【解决方案1】:

在我的应用程序中,我需要实现 CLLocationManager 并在自定义目标属性中设置 NSLocationWhenInUseUsageDescription

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    模拟器中,您需要设置自定义位置,如下所示:

    调试 > 位置 > 自定义位置... 然后输入您要模拟的位置的纬度和经度。

    注意:如果此方法不起作用,则只需选择高速公路而不是自定义位置。点击Freeway Drive后,执行与上述相同的步骤。

    【讨论】:

      【解决方案3】:
           func didTapMyLocationButton(for mapView: GMSMapView) -> Bool {
      
      
      //if want to change the camera position
      
                  if self.latDouble != 0.0 && self.longDouble != 0.0
                  {
                      let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: self.latDouble, longitude: self.longDouble, zoom: 18.0)
                      self.mapView.camera = camera
      
                  }
      
                   self.mapView.isMyLocationEnabled = true
                  self.mapView.reloadInputViews()
                  return true
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-10
        • 1970-01-01
        • 2013-08-22
        • 1970-01-01
        • 2014-06-15
        • 2020-02-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多