【发布时间】:2020-01-30 14:21:35
【问题描述】:
我正在尝试制作一个用户可以调整大小的圆形半径区域,并且我可以获得当前位置的半径数。
=================
tl;dr 已编辑
我想用 swift 将this 制作成 iOS 应用。
==================
现在,我已经创建了监听当前位置的地图。使用CLLocationManager,我正在观察它的更新位置,地图将显示我的位置。
import UIKit
import GoogleMaps
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet var mapView: GMSMapView!
// Current Location Components
var locationManager = CLLocationManager()
var didFindMyLocation = false
override func viewDidLoad() {
super.viewDidLoad()
// Current Location Delegate
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
// Observer for update location (Moving)
mapView.addObserver(self, forKeyPath: "myLocation", options: NSKeyValueObservingOptions.New, context: nil)
}
// Core Location Location Manager Delegate
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == CLAuthorizationStatus.AuthorizedWhenInUse {
mapView.myLocationEnabled = true
}
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if !didFindMyLocation {
let myLocation: CLLocation = change![NSKeyValueChangeNewKey] as! CLLocation
mapView.camera = GMSCameraPosition.cameraWithTarget(myLocation.coordinate, zoom: 18.0)
mapView.settings.myLocationButton = true
didFindMyLocation = true
}
}
现在我想做一个可调整大小的圆圈。有人已经在 android here 中创建了它。圆/半径可以通过手势缩小或扩大,我可以像question 那样从它的中心获取该圆的半径。这就是我想要的应用程序。
那么,我应该为这个可调整半径的圆使用什么?我非常感谢每一个答案和想法。谢谢!
【问题讨论】:
标签: ios swift google-maps