1
я делал проект в Swift 3.Заполните область в карте с цветом
Я выбираю очки, коснувшись на карте и после этого я связать их с линией.
Я пытался заполнить область между этими точками красным цветом, но без каких-либо успехов. Как я могу это сделать?
Я установил цвет заливки в mapview, но он не работает.
У меня есть этот код до сих пор:
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var map: MKMapView!
var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]() //all touched points
override func viewDidLoad() {
super.viewDidLoad()
map.delegate = self
let latitude: CLLocationDegrees = 38.925560
let longitude: CLLocationDegrees = -9.229723
let lanDelta: CLLocationDegrees = 0.05
let lonDelta: CLLocationDegrees = 0.05
let span = MKCoordinateSpan(latitudeDelta: lanDelta, longitudeDelta: lonDelta)
let coordinates = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
let region = MKCoordinateRegion(center: coordinates, span: span)
map.setRegion(region, animated: true)
let uilpgr = UILongPressGestureRecognizer(target: self, action: #selector(ViewController.longpress(gestureRecognizer:)))
uilpgr.minimumPressDuration = 0.5
map.addGestureRecognizer(uilpgr)
}
func longpress(gestureRecognizer: UIGestureRecognizer) {
guard gestureRecognizer.state == .began else { return }
let touchPoint = gestureRecognizer.location(in: self.map)
let coordinate = map.convert(touchPoint, toCoordinateFrom: self.map)
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotation.title = "My Place"
map.addAnnotation(annotation)
// print("longpress activated")
points.append(annotation.coordinate)
let polyline = MKPolyline(coordinates: points, count: points.count)
map.add(polyline)
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.blue
polylineRenderer.fillColor = UIColor.red
polylineRenderer.lineWidth = 5
return polylineRenderer
}
}
спасибо за ваше издание rmaddy. Все еще не удается выполнить эту работу :( –
[This] (http://stackoverflow.com/questions/17132266/free-hand-drawing-in-google-maps-ios/40240153#40240153) может помочь –