I am using google maps in ios with swift 4, i have to show a mapview in the screen, with a marker, the problem is that whenever i show the mapview i got this result:
and the result i want to get is this:
here is the code i am using:
func loadMap(location:CLLocation){
self.mapView.isMyLocationEnabled = true
self.mapView.isUserInteractionEnabled = true
self.view.layoutIfNeeded()
self.addLocationMarker()
}
func addLocationMarker(){
// Creates a marker in the center of the map.
let marker = GMSMarker()
print(self.startLocation)
marker.position = CLLocationCoordinate2D(latitude: self.startLocation.coordinate.latitude, longitude: self.startLocation.coordinate.longitude)
marker.map = self.mapView
let camera = GMSCameraPosition.camera(withLatitude: self.startLocation.coordinate.latitude, longitude: self.startLocation.coordinate.longitude, zoom: 12.0)
self.mapView.camera = camera
}
and the mapview is an outlet of a view in the storyboard
This Code works fine for me. Try this out (Swift 4)
func setupMapView() {
DispatchQueue.main.async {
let position = CLLocationCoordinate2D(latitude: 32.9483364, longitude: -96.8241543)
let marker = GMSMarker(position: position)
self.mapView.camera = GMSCameraPosition(target: position, zoom: 15, bearing: 0, viewingAngle: 0)
marker.title = "Enter marker title here"
marker.map = self.mapView
}
}
Note: I have used sample longitude and lattitude. You should insert your's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With