RxGoogleMaps 3.0.1

RxGoogleMaps 3.0.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2018
SPMSupports SPM

Maintained by Yongha Yoo, RxSwift Community.


Downloads

Total79,528
Week422
Month3,922

Installs

Apps278
Apps WeekApps This Week 35
Pod Tries4
Test Targets33
Test WeekTests This week 10
powered by Segment

GitHub

Stars31
Watchers31
Forks11
Issues1
Contributors2
Pull Requests0

Code

Files10
LOCLines of Code 562


 
Depends on:
RxSwift~> 4.0
RxCocoa~> 4.0
GoogleMaps~> 2.6.0
 

  • By
  • Yongha Yoo and RxSwift Community

RxGoogleMaps

RxGoogleMaps is a RxSwift wrapper for GoogleMaps.

Example Usages

Setup GoogleMaps

// Setup API Key
GMSServices.provideAPIKey("Your-API-Key")
// Setup GMSMapview from Interface Builder
@IBOutlet weak var mapView: GMSMapView!

or

// Setup GMSMapview
let mapView = GMSMapView(frame: self.view.bounds)
self.view.addSubview(mapView)

Observing properties

// Camera position

mapView.rx.didChangePosition.asDriver()
    .drive(onNext: { print("Did change camera position: \($0)") })
    .addDisposableTo(disposeBag)

// Marker tapped

mapView.rx.didTapMarker.asDriver()
    .drive(onNext: { print("Did tap marker: \($0)") })
    .addDisposableTo(disposeBag)

// Update marker icon without storing selection status

let s0 = mapView.rx.selectedMarker.asObservable()
let s1 = s0.skip(1)

Observable.zip(s0, s1) { $0 }
    .subscribe(onNext: { (prev, cur) in
        if let marker = prev { marker.icon = #imageLiteral(resourceName: "marker_normal") }
        if let marker = cur { marker.icon = #imageLiteral(resourceName: "marker_selected") }
    })
    .addDisposableTo(disposeBag)

Binding properties

// Properties

button.rx.tap
    .map { false }
    .bindTo(mapView.rx.trafficEnabled.asObserver())
    .addDisposableTo(disposeBag)

// Camera animations

button.rx.tap
    .map { 14 }
    .bindTo(mapView.rx.zoomToAnimate)
    .addDisposableTo(disposeBag)

button.rx.tap
    .map { GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 8, bearing: 10, viewingAngle: 30) }
    .bindTo(mapView.rx.cameraToAnimate)
    .addDisposableTo(disposeBag)

// Selected marker

button.rx.tap
    .map { myMarker }
    .bindTo(mapView.rx.selectedMarker.asObserver())
    .addDisposableTo(disposeBag)

// GMSMarker or GMSOverlay properties

button.rx.tap
    .map{ 180.0 }
    .bindTo(marker.rx.rotation.asObserver())
    .addDisposableTo(disposeBag)

button.rx.tap
    .map{ UIColor.red }
    .bindTo(circle.rx.fillColor.asObserver())
    .addDisposableTo(disposeBag)

Delegates which have a return value

// func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool

mapView.rx.handleTapMarker { false }

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

mapView.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
}

Installation

Because GoogleMaps SDK include static binaries, it’s hard to find a nice solution to make a straight-forward Cocoapods framework if it uses GoogleMaps SDK. So I decided RxGoogleMaps not to use GoogleMaps directly and to provide a bridging swift file which connects GoogleMaps and RxGoogleMaps instead.

Requirements

License

MIT