ios - 将 CLLocationCoordinate2D 和半径转换为 GMSMapView 的缩放和中心点
问题描述
我有一个中心有平方的屏幕,y坐标和固定宽度的偏移量,我需要保存平方的坐标和半径并将其发送到服务器,之后,我需要恢复屏幕状态。第一部分很简单:
let radius:CGFloat = 200
let centerYCoordinate:CGFloat = (self.view.bounds.size.height/2)-30
let left = self.mapView.projection.coordinate(for: CGPoint.init(x: (self.view.bounds.size.width/2)-radius, y: centerYCoordinate-radius))
let right = self.mapView.projection.coordinate(for: CGPoint.init(x: (self.view.bounds.size.width/2)+radius, y: centerYCoordinate-radius))
let center = self.mapView.projection.coordinate(for: CGPoint.init(x: (self.view.bounds.size.width/2), y: centerYCoordinate))
let leftLocation = CLLocation.init(latitude: left.latitude, longitude: left.longitude)
let rightLocation = CLLocation.init(latitude: right.latitude, longitude: right.longitude)
let distance = leftLocation.distance(from: rightLocation)
但是我找不到任何可能的东西如何通过中心坐标和半径恢复状态,有人有什么想法吗?
编辑:我找到了计算缩放的方法
let radius:CGFloat = 200
let screenWidhtInPoints: CGFloat = radius*2
let zoom = GMSCameraPosition.zoom(at: location, forMeters: distance, perPoints: screenWidhtInPoints)
但是我怎样才能使 y 坐标中心偏移 30 点?
解决方案
推荐阅读
- node.js - 无法在嵌入中显示本地图像?不和谐.js
- reactjs - 在生产环境中不允许我的 POST 请求
- matlab - Matconvnet 没有使用 matlab 2019 b 与 gpu 一起编译?
- flutter - 如何在另一个提供者中使用提供者
- python-3.x - Python中带有时区的日期时间
- c# - 使用 Selenium 和 C# - 如何在没有 ID 或 NAME 时填充文本框
- popper.js - Bootstrap 5 alpha 包和 popper
- pandas - 使用 pandas 插入前一天的值
- php - 我怎样才能只回显我想要的标题?php
- swift - 请求 URL 并在警报中解析结果