Created
November 17, 2020 07:29
-
-
Save dilipiOSDeveloper/9708c1518258513636306f89cb04e7d9 to your computer and use it in GitHub Desktop.
GoogleMaps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import GoogleMaps | |
import GooglePlaces | |
class ViewController: UIViewController,CLLocationManagerDelegate { | |
@IBOutlet weak var mapView: GMSMapView! | |
var coordinates: [CLLocationCoordinate2D] = [] | |
var polygonPath = GMSPolyline() | |
var bounds = GMSCoordinateBounds() | |
var placeLatLong = [latlongmodel]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let camera = GMSCameraPosition.camera(withLatitude: 53.16770568830064, longitude: -3.037760630249977, zoom: 8) | |
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) | |
mapView.isMyLocationEnabled = true | |
mapView.settings.myLocationButton = true | |
mapView.delegate = self | |
self.view = mapView | |
// Creates a marker in the center of the map. | |
let marker = GMSMarker() | |
marker.position = CLLocationCoordinate2D(latitude: 53.16770568830064, longitude: -3.037760630249977) | |
marker.map = mapView | |
marker.tracksInfoWindowChanges = true | |
} | |
func setMarker(){ | |
for value in placeLatLong{ | |
let K1 = GMSMutablePath() | |
let marker = GMSMarker() | |
K1.add(CLLocationCoordinate2D(latitude: value.lat, longitude: value.long)) | |
marker.position = CLLocationCoordinate2D(latitude: value.lat, longitude: value.long) | |
marker.map = self.mapView | |
let K1polygon = GMSPolygon(path: K1) | |
K1polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05); | |
K1polygon.strokeColor = .red | |
K1polygon.strokeWidth = 2 | |
K1polygon.isTappable = true | |
K1polygon.map = mapView | |
} | |
} | |
} | |
extension ViewController :GMSMapViewDelegate{ | |
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool { | |
print("marker tap : \(marker.title ?? "")") | |
return false | |
} | |
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) { | |
print("taped is : Latitude \(coordinate.latitude),Longitude \(coordinate.longitude)") | |
let obj = latlongmodel() | |
obj.lat = coordinate.latitude | |
obj.long = coordinate.longitude | |
placeLatLong.append(obj) | |
setMarker() | |
} | |
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) { | |
} | |
} | |
class latlongmodel { | |
var lat = 0.0 | |
var long = 0.0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment