ios - 在适用于 iOS 的 Google Maps API 上添加可调整大小的圆半径

标签 ios swift google-maps

我正在尝试制作一个用户可以调整大小的类似圆圈的半径区域,我可以获得当前位置的半径数。

================

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/

相关文章:

ios - 无法从 CoreData 中删除 NSOrderedSet

javascript - Rails - 如何将从外部 API 检索到的前端 javascript 数据发送到 Controller

android - 单击叠加层时显示 toast

android - 告诉用户他必须使用 LongClick

ios - "Cannot assign value of type ' 无效 ' to type ' PDFAction?为 PDFAnnotation 设置操作时出现 '"错误

ios - 自动调整 UITableView 的 header

ios - 什么时候从内存中删除应用程序

iOS 子类化 SKShapeNode

ios - 编译器错误表达式太复杂,无法解决

ios - 支付队列不调用观察者对象更新交易,为什么?