TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | May 2016 |
SPMSupports SPM | ✗ |
Maintained by Masahiro Watanabe.
Did you know Apple officially provides a limit-free place search API called MKLocalSearch ? MWPlaceSearch is an easy-to-use MKLocalSearch library written in Swift.
import UIKit
import MapKit
import MWPlaceSearch
class ViewController: UIViewController, MWPlaceSearchDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Find a sushi place in Vancouver
// You can provide a region as a hint. It can also be nil.
let coordinate = CLLocationCoordinate2DMake(49.282909, -123.1273396) // Vancouver
let region = MKCoordinateRegionMakeWithDistance(coordinate, 1000.0, 1000.0) // 1km * 1km
MWPlaceSearch(delegate: self).search("Sushi Vancouver", withRegion: region)
}
// This function will be called when a search had done or failed.
func didFinishSearchingPlace(result: MWPlaceSearchResult) {
switch result.response {
case .Success:
guard let data = result.data else { return }
data.forEach {
if let name = $0.name {
print("name => \(name)")
print("coordinate => \($0.placemark.coordinate.latitude), \($0.placemark.coordinate.longitude)")
print("address => \($0.placemark.address)")
}
}
case .Failure:
()
}
}
}
pod "MWPlaceSearch"
Masahiro Watanabe, [email protected]
MWPlaceSearch is available under the MIT license. See the LICENSE file for more info.