Skip to content

Instantly share code, notes, and snippets.

@Tulakshana
Last active April 6, 2016 08:41
Show Gist options
  • Save Tulakshana/442c96d00c0c2a5c940f475119b9533f to your computer and use it in GitHub Desktop.
Save Tulakshana/442c96d00c0c2a5c940f475119b9533f to your computer and use it in GitHub Desktop.
An interactive Google Map with custom interactive markers
import UIKit
import GoogleMaps
class GMInteractiveMarker: UIViewController,GMSMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.loadMap()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadMap() {
let camera = GMSCameraPosition.cameraWithLatitude(41.887,
longitude:-87.622, zoom:15)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)
mapView.delegate = self
self.addMarkers(mapView)
self.view = mapView
}
func addMarkers(mapView:GMSMapView) {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(41.887, -87.622)
marker.appearAnimation = kGMSMarkerAnimationPop
marker.icon = UIImage(named: "Map-Marker-Marker-Outside-Azure")
marker.title = "Sample location 1"
marker.map = mapView
let marker2 = GMSMarker()
marker2.position = CLLocationCoordinate2DMake(41.880, -87.622)
marker2.appearAnimation = kGMSMarkerAnimationPop
marker2.icon = UIImage(named: "Map-Marker-Marker-Outside-Azure")
marker2.title = "Sample location 2"
marker2.map = mapView
}
//MARK: - GMSMapView Delegate
func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool{
print(marker.title)
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment