-
Notifications
You must be signed in to change notification settings - Fork 5
/
ViewController.swift
48 lines (38 loc) · 1.65 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// ViewController.swift
// GoogleMapSwift
//
// Created by Ziyang Tan on 2/10/15.
// Copyright (c) 2015 Ziyang Tan. All rights reserved.
//
import UIKit
class ViewController: UIViewController, GMSMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
mapView.delegate = self
self.view = mapView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
var infoWindow = NSBundle.mainBundle().loadNibNamed("CustomInfoWindow", owner: self, options: nil).first! as CustomInfoWindow
infoWindow.label.text = "\(marker.position.latitude) \(marker.position.longitude)"
return infoWindow
}
func getDistanceMetresBetweenLocationCoordinates(coord1: CLLocationCoordinate2D, coord2: CLLocationCoordinate2D) -> Double {
var location1 = CLLocation(latitude: coord1.latitude, longitude: coord1.longitude)
var location2 = CLLocation(latitude: coord2.latitude, longitude: coord2.longitude)
return location1.distanceFromLocation(location2)
}
}