KZY
KZY

Reputation: 91

How to check and load coordinate into Google Map (iOS)?

I have a list of coordinates in database, but i would like to load only the coordinates that currently in the view of Google Map and add a marker onto it. How can i do that ?

Upvotes: 0

Views: 515

Answers (1)

rxtr007
rxtr007

Reputation: 121

Once you get latitude and longitude, you can use the following function to add map marker and zoom to marker location :

func showMapMarker() {
    self.currentLocationMapView.clear()

    DispatchQueue.main.async {

        let position = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
        let marker = GMSMarker(position: position)
        let bounds: GMSCoordinateBounds = GMSCoordinateBounds(coordinate: position, coordinate: position)
        marker.title = "Snippet Title"
        marker.map = self.currentLocationMapView
        marker.snippet = "Snippet Text"
        let camera = self.currentLocationMapView.camera(for: bounds, insets: UIEdgeInsets())
        self.currentLocationMapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 15.0))
        self.currentLocationMapView.camera = camera!
    }
}

Upvotes: 1

Related Questions