MKLocalSearch查找附近的条形图,由其他视图控制器上的按钮触发

时间:2018-06-12 08:05:27

标签: ios swift

我正在开发一款应用,可以帮助用户找到当前用户位置周围1000 m附近的附近酒吧。我的一个视图控制器包含一个"SEARCH NEARBY BARS"按钮。按下时,我想打开下一个视图控制器(包含MKMapView)并自动运行搜索,这与用户必须将其自身输入搜索栏相反。这是我的代码:

import UIKit
import MapKit

class BarVC: UIViewController {

@IBOutlet weak var backBtn: UIButton!

@IBOutlet weak var barMapBtn: UIButton!

@IBAction func backBtnWasPressed(_ sender: Any) {
    dismiss(animated: true)
}

@IBAction func barMapBtnWasPressed(_ sender: Any) {
}

let regionRadius: Double = 1000

var locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()

    guard let coordinate = locationManager.location?.coordinate else { 
return }
    let coordinateRegion = 
MKCoordinateRegionMakeWithDistance(coordinate, regionRadius * 2.0, 
regionRadius * 2.0)

    let request = MKLocalSearchRequest()
    request.naturalLanguageQuery = "bars"
    request.region = coordinateRegion

    let search = MKLocalSearch(request: request)
        search.start(completionHandler: 
<#T##MKLocalSearchCompletionHandler##MKLocalSearchCompletionHandler## 
(MKLocalSearchResponse?, Error?) -> Void#>)

        search.cancel()

 }

 }

我如何进行此操作并显示用户周围的所有附近酒吧?我会集成GoogleMaps/GooglePlaces API,但我的终端目前在下载Cocoapods时遇到问题。请帮忙!

0 个答案:

没有答案