I'm using google map iOS in my app , i want to show custom marker info window.How can i create it? I'm using storyboards and swift as the language.
Adding a marker To add a marker, create a GMSMarker object that includes a position and title , and set its map . The following example demonstrates how to add a marker to an existing GMSMapView object. The marker is created at coordinates 10,10 , and displays the string "Hello world" in an info window when clicked.
Move an info windowAttach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.
You can delete the markers by removing them from the map and then setting the array's length to 0 , which removes all references to the markers.
I had one such problem with my app.
In your ViewController.swift:
class ViewController: GMSMapViewDelegate {
func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView? {
let placeMarker = marker as! PlaceMarker
if let infoView = UIView.viewFromNibName("MarkerInfoView") as? MarkerInfoView {
infoView.nameLabel.text = placeMarker.place.name
if let photo = placeMarker.place.photo {
infoView.placePhoto.image = photo
} else {
infoView.placePhoto.image = UIImage(named: "generic")
}
return infoView
} else {
return nil
}
}
}
2.Then create a UIView class:
import UIKit
class MarkerInfoView: UIView {
@IBOutlet weak var placePhoto: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
}
Note that the class name is the same as UIView class. You can add label and images as per your requirement. Connect those IBOutlets to the UIView class as shown.
Hope this helps you. All the Best!
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