Skip to content

Commit

Permalink
Added Initial coordinate and initial zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbernad committed Jul 9, 2019
1 parent 33a2d86 commit 8bf1451
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion PlacesPicker/Classes/PlacePickerConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public struct PlacePickerConfig {
public let placeFields: GMSPlaceField
public let pickerRenderer: PickerRenderer
public let placesFilter: GMSAutocompleteFilter?
public let initialCoordinate: CLLocationCoordinate2D?
public let initialZoom: Float

public static var `default`: PlacePickerConfig {
return PlacePickerConfig()
Expand All @@ -22,11 +24,15 @@ public struct PlacePickerConfig {
public init(listRenderer: PlacesListRenderer = DefaultPlacesListRenderer(),
placeFields: GMSPlaceField = GMSPlaceField.defaultFields,
placesFilter: GMSAutocompleteFilter? = nil,
pickerRenderer: PickerRenderer = DefaultPickerRenderer()) {
pickerRenderer: PickerRenderer = DefaultPickerRenderer(),
initialCoordinate: CLLocationCoordinate2D? = nil,
initialZoom: Float = 13.0) {
self.listRenderer = listRenderer
self.placeFields = placeFields
self.placesFilter = placesFilter
self.pickerRenderer = pickerRenderer
self.initialZoom = initialZoom
self.initialCoordinate = initialCoordinate
}
}

Expand Down
8 changes: 8 additions & 0 deletions PlacesPicker/Classes/PlacePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public class PlacePickerController: UIViewController, PlacesDataSourceDelegate {
public override func viewDidLoad() {
super.viewDidLoad()
setupNavigationBar()
setInitialCoordinateIfNeeded()
}

private func setInitialCoordinateIfNeeded() {
if let initialCoordinate = self.config.initialCoordinate {
let position = GMSCameraPosition(latitude: initialCoordinate.latitude, longitude: initialCoordinate.longitude, zoom: config.initialZoom)
pickerView.mapView.animate(to: position)
}
}

// Internal
Expand Down
6 changes: 4 additions & 2 deletions PlacesPicker/Classes/PlacesDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ extension PlacesDataSource: UITableViewDataSource {
extension PlacesDataSource: GMSAutocompleteViewControllerDelegate {
public func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
self.state = .singlePlace(place: place)
self.delegate?.autoCompleteControllerDidProvide(place: place)
viewController.dismiss(animated: true, completion: nil)

viewController.dismiss(animated: true, completion: { [weak self] in
self?.delegate?.autoCompleteControllerDidProvide(place: place)
})
}

public func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
Expand Down

0 comments on commit 8bf1451

Please sign in to comment.