【问题标题】:Get lat/long from the google mapview从谷歌地图视图获取纬度/经度
【发布时间】:2018-01-18 10:07:45
【问题描述】:

我需要获取用户在谷歌地图视图上点击的位置的纬度/经度。是否有必要为此打开 GooglePlacePickerViewController?我需要在用于显示用户当前位置的 GMSMapView 中实现这一点。

【问题讨论】:

  • GooglePlacePickerViewController 不需要。浏览此Doc 并使用mapView:didTapAtCoordinate:

标签: ios swift google-maps location


【解决方案1】:

使用Delegate方法很简单

第一组委托

    self.mapView.delegate = self

那么就

extension YourViewController:GMSMapViewDelegate {


   func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {

       // USER TAP ON  coordinate
   }
}

建议:只需阅读本教程https://medium.freecodecamp.org/how-you-can-use-the-google-maps-sdk-with-ios-using-swift-4-a9bba26d9c4d 不会超过 20 分钟,我的承诺将涵盖所有基本内容。 :)

如果您需要基于观点的系统。例如,如果您想要用户根据视图 X、Y 轻按的确切点是什么

然后

你可以这样做

let points:CGPoint = mapView.projection.point(for:coordinates)

宾果!!

【讨论】:

    【解决方案2】:

    像这样分配委托。

    mapView.delegate = self
    

    并使用GMSMapViewDelegate 使用下面的方法

    func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
            print("You tapped at Location \(coordinate.latitude), \(coordinate.longitude)")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      • 2017-12-04
      • 2014-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多