RxSwiftCommunity/RxGoogleMaps

Name: RxGoogleMaps

Owner: RxSwift Community

Description: RxSwift reactive wrapper for GoogleMaps SDK

Created: 2016-10-09 17:14:10.0

Updated: 2018-05-18 08:48:05.0

Pushed: 2018-02-28 15:09:37.0

Homepage: null

Size: 127

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

RxGoogleMaps

CircleCI Swift Version License Platform

RxGoogleMaps is a RxSwift wrapper for GoogleMaps.

Example Usages
Setup GoogleMaps
etup API Key
ervices.provideAPIKey("Your-API-Key")
wift
etup GMSMapview from Interface Builder
utlet weak var mapView: GMSMapView!

or

etup GMSMapview
mapView = GMSMapView(frame: self.view.bounds)
.view.addSubview(mapView)
Observing properties
amera position

iew.rx.didChange.asDriver()
.drive(onNext: { print("Did change position: \($0)") })
.disposed(by: disposeBag)

arker tapped

iew.rx.didTapAt.asDriver()
.drive(onNext: { print("Did tap at coordinate: \($0)") })
.disposed(by: disposeBag)

ocation update

iew.rx.myLocation
.subscribe(onNext: { location in
    if let l = location {
        print("My location: (\(l.coordinate.latitude), \(l.coordinate.longitude))")
    } else {
        print("My location: nil")
    }
})
.disposed(by: disposeBag)
Binding properties
roperties

on.rx.tap
.map { false }
.bind(to: mapView.rx.trafficEnabled.asObserver())
.disposed(by: disposeBag)

amera animations

on.rx.tap
.map { 14 }
.bind(to: mapView.rx.zoomToAnimate)
.disposed(by: disposeBag)

on.rx.tap
.map { GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 8, bearing: 10, viewingAngle: 30) }
.bind(to: mapView.rx.cameraToAnimate)
.disposed(by: disposeBag)

elected marker

on.rx.tap
.map { myMarker }
.bind(to: mapView.rx.selectedMarker.asObserver())
.disposed(by: disposeBag)

MSMarker or GMSOverlay properties

on.rx.tap
.map{ 180.0 }
.bind(to: marker.rx.rotation.asObserver())
.disposed(by: disposeBag)

on.rx.tap
.map{ UIColor.red }
.bind(to: circle.rx.fillColor.asObserver())
.disposed(by: disposeBag)
Delegates which have a return value
unc mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool

iew.rx.handleTapMarker { false }

unc mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView?

iew.rx.handleMarkerInfoWindow { marker in
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 180, height: 60))
label.textAlignment = .center
label.textColor = UIColor.brown
label.font = UIFont.boldSystemFont(ofSize: 16)
label.backgroundColor = UIColor.yellow
label.text = marker.title
return label

Note: More examples can be found at the example project from this repo!.

Installation
CocoaPods

Note: Due to the fact Google Maps is delivered as a static library, you must have CocoaPods 1.4.0 installed to install this library.

'RxGoogleMaps'

Than run pod install, and you should be good to go!

Example Project
  1. Get your own API Key a key at https://developers.google.com/maps/documentation/ios-sdk/
  2. Open the example project and set your API Key in AppDelegate
Requirements
License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.