import UIKit
import GoogleMaps
class ReportLocationDetailViewController: UIViewController {
var event : ReportDetail?;
@IBOutlet weak var mapView: GMSMapView!;
@IBOutlet weak var zoomInBtn: UIButton!;
@IBOutlet weak var zoomOutBtn: UIButton!;
@IBAction func dismissAction(){
self.dismiss(animated: true) {
}
}
@IBAction func zoomIn(){
self.mapView.animate(with: GMSCameraUpdate.zoomIn());
}
@IBAction func zoomOut(){
self.mapView.animate(with: GMSCameraUpdate.zoomOut());
}
func setUpUI(){
self.zoomInBtn.layer.cornerRadius = 2.0;
self.zoomInBtn.layer.masksToBounds = true;
self.zoomInBtn.layer.borderColor = UIColor.lightGray.cgColor;
self.zoomInBtn.layer.borderWidth = 1.0;
self.zoomInBtn.imageEdgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5);
self.zoomOutBtn.layer.cornerRadius = 2.0;
self.zoomOutBtn.layer.masksToBounds = true;
self.zoomOutBtn.layer.borderColor = UIColor.lightGray.cgColor;
self.zoomOutBtn.layer.borderWidth = 1.0;
self.zoomOutBtn.imageEdgeInsets = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5);
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews();
self.setUpUI();
}
override func viewDidLoad() {
super.viewDidLoad()
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated);
if let e = self.event, let lat = e.lat, let lon = e.lon{
let position = CLLocationCoordinate2D(latitude: lat, longitude: lon)
let marker = GMSMarker(position: position);
marker.snippet = e.address;
marker.title = e.name;
marker.groundAnchor = CGPoint(x: -6.5, y: -3.0);
marker.map = mapView;
self.mapView.selectedMarker = marker;
let update = GMSCameraUpdate.setTarget(position, zoom: 15)
self.mapView.animate(with: update);
}
}
}
Map view with correct position
MapView After Zoom In
MapView After Zoom Out