그리기 응용 프로그램에서 사용자가 그림을 그리거나 선을 그어 모양을 만들기 시작할 때 식별 할 수 있습니다. 지도에서 동일한 작업을 수행하려고 시도 중이므로 누구나 코드를 사용하여 도움을받을 수 있습니다. 또는 git 프로젝트Google지도에서 무료 손 그리기 - iOS
답변
라인을 그리려면 polyline
을 사용하십시오. Google Maps Shapes을 참조하십시오.
polyline
을 사용하려면 locatoin 좌표를 지정해야합니다. 화면상의 한 점을 coordinateForPoint:(CGPoint)point
방법 GMSProjection 클래스의 좌표로 변환하려면.
Polyline
은 실제로 두 좌표 사이에 선을 그립니다. 따라서 움직이는 mapView와 함께이 선들도 움직입니다. 나는 이것이 당신이 원하는 것이라고 생각합니다.
@liva 사용자가 화면에 손가락을 대고 끌 때 사용자가지도를 스크롤하여 다른 위치를 보거나 사진을 그리기를 원할 때 어떻게 결정할 수 있기 때문에 어떻게 구현할 수 있을까요? – Geek
Map Kit Polyline or Polygon Drawing - https://github.com/tazihosniomar/MapKitDrawing
이 링크는 애플지도에 다각형을 그리기위한 데모 프로젝트가 포함되어 있습니다. 그러나 Google Map View의 논리는 동일하게 유지됩니다. 따라서 구현 로직을 복사하여 Google Map에 적용 할 수 있습니다.
이 정보가 도움이되기를 바랍니다.
기본 단계를 포함합니다 : 사용자가 그리는 시작할 때마다
1) 는 오버레이보기를 추가합니다.
lazy var canvasView:CanvasView = {
var overlayView = CanvasView(frame: self.googleMapView.frame)
overlayView.isUserInteractionEnabled = true
overlayView.delegate = self
return overlayView
}()
@IBAction func drawActn(_ sender: AnyObject?) {
self.coordinates.removeAll()
self.view.addSubview(canvasView)
let origImage = UIImage(named: "pen")
let tintedImage = origImage?.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
drawBtn.setImage(tintedImage, for: .normal)
drawBtn.tintColor = UIColor.white
drawBtn.backgroundColor = UIColor.red
}
2) 오버레이보기에 그리기 무료 손 마십시오.
class CanvasView: UIImageView {
weak var delegate:NotifyTouchEvents?
var lastPoint = CGPoint.zero
let brushWidth:CGFloat = 3.0
let opacity :CGFloat = 1.0
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
self.delegate?.touchBegan(touch: touch)
lastPoint = touch.location(in: self)
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
self.delegate?.touchMoved(touch: touch)
let currentPoint = touch.location(in: self)
drawLineFrom(fromPoint: lastPoint, toPoint: currentPoint)
lastPoint = currentPoint
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
self.delegate?.touchEnded(touch: touch)
}
}
func drawLineFrom(fromPoint: CGPoint, toPoint: CGPoint) {
UIGraphicsBeginImageContext(self.frame.size)
let context = UIGraphicsGetCurrentContext()
self.image?.draw(in: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))
context?.move(to: fromPoint)
context?.addLine(to: toPoint)
context?.setLineCap(.round)
context?.setLineWidth(brushWidth)
context?.setStrokeColor(UIColor.black.cgColor)
context?.setBlendMode(.normal)
context?.strokePath()
self.image = UIGraphicsGetImageFromCurrentImageContext()
self.alpha = opacity
UIGraphicsEndImageContext()
}
}
3)
대리자 패턴을 다각형으로 좌표//MARK: GET DRAWABLE COORDINATES
extension ViewController:NotifyTouchEvents{
func touchBegan(touch:UITouch){
let location = touch.location(in: self.googleMapView)
let coordinate = self.googleMapView.projection.coordinate(for: location)
self.coordinates.append(coordinate)
}
func touchMoved(touch:UITouch){
let location = touch.location(in: self.googleMapView)
let coordinate = self.googleMapView.projection.coordinate(for: location)
self.coordinates.append(coordinate)
}
func touchEnded(touch:UITouch){
let location = touch.location(in: self.googleMapView)
let coordinate = self.googleMapView.projection.coordinate(for: location)
self.coordinates.append(coordinate)
createPolygonFromTheDrawablePoints()
}
}
4) 변경하여 제어 할 수 있도록 OverlayView로부터 어레이의 모든 좌표를 취득.
func createPolygonFromTheDrawablePoints(){
let numberOfPoints = self.coordinates.count
//do not draw in mapview a single point
if numberOfPoints > 2 { addPolyGonInMapView(drawableLoc: coordinates) }//neglects a single touch
coordinates = []
self.canvasView.image = nil
self.canvasView.removeFromSuperview()
let origImage = UIImage(named: "pen")
let tintedImage = origImage?.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
drawBtn.setImage(tintedImage, for: .normal)
drawBtn.tintColor = UIColor.red
drawBtn.backgroundColor = UIColor.white
}
func addPolyGonInMapView(drawableLoc:[CLLocationCoordinate2D]){
isDrawingModeEnabled = true
let path = GMSMutablePath()
for loc in drawableLoc{
path.add(loc)
}
let newpolygon = GMSPolygon(path: path)
newpolygon.strokeWidth = 3
newpolygon.strokeColor = UIColor.black
newpolygon.fillColor = UIColor.black.withAlphaComponent(0.5)
newpolygon.map = googleMapView
if cancelDrawingBtn.isHidden == true{ cancelDrawingBtn.isHidden = false }
userDrawablePolygons.append(newpolygon)
addPolygonDeleteAnnotation(endCoordinate: drawableLoc.last!,polygon: newpolygon)
}
나는 스위프트 3 here 구글지도에 여러 개의 폴리곤을 삭제/그리기 위해 데모 프로젝트를 만들었습니다.
AppDelegate에서 API 키를 설정하고 프로젝트를 실행하기 위해 번들 식별자를 변경하는 것을 기억하십시오.
- 1. Google지도에서 그리기
- 2. Google지도에서 경로 그리기
- 3. Google지도에서 라인 그리기
- 4. Google지도에서 여러 마커 그리기
- 5. Google지도에서 다각형 그리기
- 6. Google지도에서 익명 원 그리기
- 7. 손 움직임을 사용하여 LED 패널에 모양 그리기
- 8. Google지도에서 폴리선을 그리기 가능하지 않게하십시오
- 9. Google지도에서 폴리선 화살표 그리기 V2
- 10. Google지도에서 마커 제거 iOS
- 11. 손
- 12. URL에 매개 변수를 전달하여 Google지도에서 원 그리기
- 13. 두 점에 수직 인 Google지도에서 선 그리기
- 14. MapKit 프레임 워크로 Google지도에서 다각형 그리기
- 15. 클라이언트에서 서버로 위치를 보내고 Google지도에서 그림 그리기
- 16. 자바 스크립트를 사용하여 Google지도에서 다각형 그리기
- 17. Google지도에서 깜박이는 맞춤 마커 iOS
- 18. fabric.js : 모양을 그리기 위해 자유로운 손 모양을 채우는 방법은 무엇입니까?
- 19. JAVA에 무료 그리기 도구 API가 있습니까?
- 20. 직선 그리기 iOS
- 21. IOS : 손가락으로 선 그리기
- 22. iOS : MKMapView에 텍스트 그리기
- 23. iOS 그리기 서클
- 24. IOS 그리기 줄 터치
- 25. iOS - 그라디언트 그리기 - Swift
- 26. 효율적으로 손
- 27. 왼쪽 손
- 28. ios 용 arcgis지도에서 자유 그리기
- 29. iOS OpenGL ES - 요청시 그리기
- 30. iOS : UIView 내에 그림자 그리기
안녕하세요, 저는 실제로 똑같은 것을 시도하고 있습니다. 무엇인가 발견하면 저를 도울 수 있습니까? –
@ 리브 a : 이것에 대한 해결책이 있습니까? 한 가지 방법은지도 스크롤을 활성화/비활성화하는 버튼을 배치하는 것입니다. 다른 방법이 있습니까? – Mrug