나는 마커에 관해이 작은 질문을 가지고있다. 사용자가 내 Google지도 기반 앱에 자신의 마커를 배치하도록하려면 어떻게해야합니까?사용자가지도에 마커를 배치하는 방법?
-4
A
답변
0
여기에는 여러 가지 방법이 있습니다. 그 중 하나는 사용자가지도를 오랫동안 누르면 마커를 추가하는 것입니다. 긴 프레스를 감지하기 위해이 위임 메서드를 구현 : 그들은 단지 마커의 사용자 지정 특성을 설정하는로
func mapView(_ mapView: GMSMapView, didLongPressAt coordinate: CLLocationCoordinate2D) {
let marker = GMSMarker(position: coordinate)
// marker.isDraggable = true
// marker.appearAnimation = kGMSMarkerAnimationPop
marker.map = mapView
// marker.icon = GMSMarker.markerImage(with: UIColor.blue)
}
주석 처리 된 라인은 선택 사항입니다. 더 많은 것을 사용자 지정할 수 있습니다. 아직 수행하지 않은 경우
또한, 뷰 컨트롤러 클래스에 GMSMapViewDelegate
추가 '를 선언 :
class YourViewController: UIViewController, GMSMapViewDelegate {
과 delegate
속성에 self
을 할당 : 또는
let camera = GMSCameraPosition.camera(withLatitude: 0, longitude: 0, zoom: 3)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.isMyLocationEnabled = true
view = mapView
mapView.delegate = self // add this line!
, 당신을 다른 이벤트가 발생할 때 마커를 추가 할 수 있습니다. 예를 들어 사용자가 UIBarBUttonItem
또는 UIButton
을 탭하면 표시자를 추가 할 수 있습니다. 그것은 당신에게 달려 있습니다! 나중에 수정할 수 있도록 또한 컬렉션에 마커를 추가하는 것을 고려 할 수
let marker = GMSMarker(position: coordinate)
marker.map = mapView
// mapView is the map that you want to add the marker to. If you are doing this outside a delegate method, use self.view
:하지만 버튼을 추가하는 프로세스는 기본적으로이 두 줄입니다.
내 대답이 귀하의 질문에 대한 답변이라고 생각하시면 해당 체크 표시를 클릭하여 수령을 고려하십시오! @색욕 – Sweeper