How to focus on a specific location by using google maps.
-
Hi, I want to pass coordinates from FirstVC to my SecondVC. and inside the SecondVC which holds MyMap I want the map to show the coordinates I've sent from the FirstVC to do this Here is what I did. SecondVC
override func viewDidLoad() {
super.viewDidLoad()//Mapview Settings. self.MyMapView.delegate = self self.MyMapView.isMyLocationEnabled = true self.MyMapView.settings.myLocationButton = true
}
I have this Function
func InitGoogleMaps(pMyMapInf:MyMapInf){
if (pMyMapInf.IsEmpty) { return } let camera = GMSCameraPosition.camera(withLatitude: pMyMapInf.MyDestinLongitute, longitude: pMyMapInf.MyDestinLongitute, zoom: 6.0) let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) MyMapView = mapView MyMapView.isMyLocationEnabled = true self.MyMapView.camera = camera // Creates a marker in the center of the map. let marker = GMSMarker() marker.position = CLLocationCoordinate2D(latitude: pMyMapInf.MyDestinLatitude, longitude: pMyMapInf.MyDestinLongitute) marker.title = pMyMapInf.MyDestinCity marker.snippet = pMyMapInf.MyDestinCountry print("Latitude is: \\(pMyMapInf.MyDestinLatitude) ") print("Longitude is: \\(pMyMapInf.MyDestinLongitute) ") print("City is: \\(pMyMapInf.MyDestinCity) ") print("Country is: \\(pMyMapInf.MyDestinCountry) ") marker.map = mapView MyMapView.animate(to: camera)
}
And I have this Observer to trigger the above function.
var MyMapInfo:MyMapInf = MyMapInf()
{
didSet{
InitGoogleMaps(pMyMapInf: MyMapInfo)
}
}so what happens is: on my FirstVC I create a new instance of MyMapInf()
var loFVcMyMapInf = MyMapInf()
SecondVC.MyMapInfo = loFVcMyMapInfand I present the SecondVC(or I present the SecondVC then set didset observer , When this happens I see that my function is triggered and I see the values I print on the console, however, there ain't any movements on the map or a marker. it's still what am I missing here?