我正在尝试制作一个用户可以调整大小的类似圆圈的半径区域,我可以获得当前位置的半径数。
================
tl;dr 已编辑
我想制作 this作为带有 swift 的 iOS 应用程序。
=================
现在,我已经创建了监听当前位置的 map 。使用 CLLocationManager
,我正在观察它的更新位置, map 将显示我的位置。
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 .这就是我想要的应用程序。
那么,我应该为这个 radius-circle-resizable 使用什么?我真的很感激每一个答案和想法。谢谢!
最佳答案
我会创建一个多边形/圆形作为叠加层。
https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_circle
例如:
let circle = GMSCircle()
circle.radius = 130 // Meters
circle.fillColor = UIColor.redColor()
circle.position = CLLOCATION.coordinate // Your CLLocationCoordinate2D position
circle.strokeWidth = 5;
circle.strokeColor = UIColor.blackColor()
circle.map = mapView; // Add it to the map
调整它的大小,我会用 UIView 覆盖整个屏幕,并启用 UIPanGestureRecognizer
查看此处的示例: Resizable Centered Circular UIView
关于ios - 在适用于 iOS 的 Google Maps API 上添加可调整大小的圆半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38583242/