从 google 地图视图中获取 lat/long
Get lat/long from the google mapview
我需要获取用户在 google 地图视图上点击的位置的 lat/long。是否有必要为此打开 GooglePlacePickerViewController?我需要在用于显示用户当前位置的 GMSMapView 中实现这一点。
使用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)
宾果!
像这样分配代表。
mapView.delegate = self
并使用GMSMapViewDelegate
使用下面的方法
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("You tapped at Location \(coordinate.latitude), \(coordinate.longitude)")
}
我需要获取用户在 google 地图视图上点击的位置的 lat/long。是否有必要为此打开 GooglePlacePickerViewController?我需要在用于显示用户当前位置的 GMSMapView 中实现这一点。
使用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)
宾果!
像这样分配代表。
mapView.delegate = self
并使用GMSMapViewDelegate
使用下面的方法
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("You tapped at Location \(coordinate.latitude), \(coordinate.longitude)")
}