Код
import UIKit
import GooglePlaces
import GoogleMaps
class FirstViewController: UIViewController {
@IBOutlet weak var mapsView: GMSMapView!
var resultsViewController: GMSAutocompleteResultsViewController?
var searchController: UISearchController?
var pick:UISearchController!
var drop:UISearchController!
var marker:GMSMarker!
var cgrectfordrop:CGRect?
var resultView: UITextView?
var gmspick:GMSAutocompleteResultsViewController!
var gmsdrop:GMSAutocompleteResultsViewController!
override func viewDidLoad() {
super.viewDidLoad()
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
self.mapsView=mapView
resultsViewController = GMSAutocompleteResultsViewController()
resultsViewController?.delegate = self
gmspick=GMSAutocompleteResultsViewController()
gmspick.delegate=self
gmspick.accessibilityLabel="picku"
pick=UISearchController(searchResultsController: gmspick)
pick.searchResultsUpdater = gmspick
pick.searchBar.sizeToFit()
pick.searchBar.accessibilityIdentifier="picku"
pick.searchBar.placeholder="Enter pick up location"
pick.hidesNavigationBarDuringPresentation = false
pick.searchBar.sizeToFit()
gmsdrop=GMSAutocompleteResultsViewController()
gmsdrop.delegate=self
gmsdrop.accessibilityLabel="dropu"
drop=UISearchController(searchResultsController: gmsdrop)
drop.searchResultsUpdater = gmsdrop
drop.searchBar.placeholder="Enter drop location"
drop.searchBar.sizeToFit()
drop.hidesNavigationBarDuringPresentation = false
drop.searchBar.sizeToFit()
let pickyvalue=view.frame.height/2-
pick.searchBar.frame.height/2
// cgrectfordrop=CGRect(x: 0, y: pickyvalue/3.9, width:
view.frame.width, height: 45.0)
let subViewpick = UIView(frame: CGRect(x: 0, y: pickyvalue/9,
width: view.frame.width, height: 45.0))
subViewpick.addSubview(pick.searchBar)
view.addSubview(subViewpick)
let dropyvalue=view.frame.height/2-drop.searchBar.frame.height/2
// cgrectfordrop=CGRect(x: 0, y: dropyvalue/11, width:
view.frame.width, height: 45.0)
let subViewpickd = UIView(frame: CGRect(x: 0, y: dropyvalue/3,
width: view.frame.width, height: 45.0))
subViewpickd.addSubview(drop.searchBar)
view.addSubview(subViewpickd)
}
func settingmarker(location:CLLocationCoordinate2D){
self.mapsView.animate(toLocation: location)
}
}
extension FirstViewController:
GMSAutocompleteResultsViewControllerDelegate {
func resultsController(_ resultsController:
GMSAutocompleteResultsViewController,
didAutocompleteWith place: GMSPlace) {
if (resultsController.accessibilityLabel=="picku") {
pick.isActive=false
print("Place name: \(place.name)")
print("Place address: \(place.formattedAddress)")
print("Place attributions: \(place.attributions)")
print("pickup")
settingmarker(location: place.coordinate)
}else if(resultsController.accessibilityLabel=="dropu"){
drop.isActive=false
print("Place name: \(place.name)")
print("Place address: \(place.formattedAddress)")
print("Place attributions: \(place.attributions)")
print("dropu")
}
}
func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
didFailAutocompleteWithError error: Error){
// TODO: handle the error.
print("Error: ", error.localizedDescription)
}
// Turn the network activity indicator on and off again.
func didRequestAutocompletePredictions(forResultsController resultsController: GMSAutocompleteResultsViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}
func didUpdateAutocompletePredictions(forResultsController resultsController: GMSAutocompleteResultsViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
}
Невозможно обновить мой Gmsmapview при вызове функции установки маркера.
Невозможно обновить мой Gmsmapview при вызове функции установки маркера. Невозможно обновить мой Gmsmapview при вызове функции установки маркера.
Невозможно обновить мой Gmsmapview при вызове функции установки маркера.
Невозможно обновить мой Gmsmapview при вызове функции установки маркера