Skip to content

Instantly share code, notes, and snippets.

@jeckymodi
Created October 27, 2019 12:25
Show Gist options
  • Save jeckymodi/c06c5e056460b3035f4f2bf2febff26e to your computer and use it in GitHub Desktop.
Save jeckymodi/c06c5e056460b3035f4f2bf2febff26e to your computer and use it in GitHub Desktop.
Google map pin drop animation
//
// ViewController.swift
// GoogleMapPinDropAnimation
//
// Created by Jecky Modi on 27/10/19.
// Copyright © 2019 Jecky Modi. All rights reserved.
//
import UIKit
import GoogleMaps
class ViewController: UIViewController {
@IBOutlet weak var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
mapView.camera = camera
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.icon = UIImage(named: "pin")
marker.snippet = "Australia"
mapView.animate(to: camera)
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
let viewPoints = self.mapView.projection.point(for: CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20))
print(viewPoints)
let pinView = UIView(frame: CGRect(x: viewPoints.x - 22, y: viewPoints.y - 200, width: 44, height: 44))
let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
imgView.image = UIImage(named : "pin")
pinView.addSubview(imgView)
self.view.addSubview(pinView)
UIView.animate(withDuration: 1.0, delay: 0.5, options: .curveEaseInOut, animations: {
pinView.frame = CGRect(x: viewPoints.x - 22, y: viewPoints.y - 22, width: 44, height: 44)
self.view.layoutIfNeeded()
}) { (value) in
marker.map = self.mapView
UIView.animate(withDuration: 0.2, animations: {
pinView.alpha = 0.0
self.view.layoutIfNeeded()
})
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment