-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailViewControlller.swift
68 lines (52 loc) · 2.25 KB
/
DetailViewControlller.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// DetailViewControlller.swift
// Projeto Final GADS T2
//
// Created by Henrique on 9/23/16.
// Copyright © 2016 Henrique.Zwicker. All rights reserved.
//
import UIKit
import MapKit
import CoreLocation
class DetailViewController: UIViewController , CLLocationManagerDelegate {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var lblEndereco: UILabel!
@IBOutlet weak var lblName: UILabel!
var dicPlace:NSDictionary?
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
if dicPlace != nil {
imageView.image = UIImage(named: dicPlace!["image"] as! String)
lblName.text = dicPlace!["name"] as? String
lblEndereco.text = dicPlace!["address"] as? String
ActionGeocoder()
}
}
func ActionGeocoder() {
let geoCoder = CLGeocoder ()
geoCoder.geocodeAddressString(lblEndereco.text!) { (placemarks, error) -> Void in
if let placemark:CLPlacemark = placemarks?[0]{
let location = placemark.location
if let coords:CLLocationCoordinate2D = location?.coordinate {
print("Latitude = \(coords.latitude) , Longitude = \(coords.longitude)")
let span = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)
let region = MKCoordinateRegion(center: coords, span: span)
self.mapView.setRegion(region, animated: false)
let annotation = MKPointAnnotation()
annotation.coordinate = coords
annotation.title = self.dicPlace!["name"] as? String
annotation.subtitle = self.dicPlace!["address"] as? String
self.mapView.addAnnotation(annotation)
}
}
else{
print("Geocode falhou. Deu error")
}
}
}
}