CafeNomad — GoogleMap and ContainerView

Feature update!

Now can check the map to find which coffee shop is better around you. Every time select a marker, table view will display it’s info on the top.

2 Demo feature:

  1. GoogleMap

Add GMSMarker to the map

func createMarkers(shops: [Shop]) {for shop in shops {// marker initlet marker = GMSMarker()if let latitude = Double(shop.latitude!), let longitude = Double(shop.longitude!) {marker.position = CLLocationCoordinate2D(latitude: latitude , longitude: longitude)}// markers setupmarker.title = shop.namemarker.snippet = shop.open_timemarker.map = self.mapViewself.shops.append(shop)}}

2. Container View

For a easy way to setup a map that does not cover the whole view, I choose container view to separate the scene and using unwind segue to pass the tap marker data to the table view controller.

extension MapViewController: GMSMapViewDelegate {// Tap the marker thenfunc mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {selectedMarker = marker// Find the shop information by checking through the arrayfor shop in shops {if shop.name == marker.title {//  append the info to arrayself.textLabel.insert(marker.title!, at:0)// send shop info to table viewperformSegue(withIdentifier: PropertyKeys.unwindToPlaces, sender: marker)}}// return true if you want to close the marker after tapreturn false}}

In Table View Controller:

class PlacesTableViewController: UITableViewController {var textLabel = [String]()var detailTextLabel = [String]()// unwind segue IBAction setup@IBAction func unwindToPlacesTVC(segue: UIStoryboardSegue) {let source = segue.source as? MapViewControllerif let textLabel = source?.textLabel, let detailTextLabel = source?.detailTextLabel {self.textLabel = textLabelself.detailTextLabel = detailTextLabelself.tableView.reloadData()}}

Github:

--

--