Latest 0.1.0
Homepage https://github.com/mshrwtnb/MWPlaceSearch
License MIT
Platforms ios 8.0
Frameworks MapKit
Authors

[![CI Status](http://img.shields.io/travis/Masahiro Watanabe/MWPlaceSearch.svg?style=flat)](https://travis-ci.org/Masahiro Watanabe/MWPlaceSearch)
Version
License
Platform

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.

  • Search with a natural query like ‘Sushi Vancouver’
  • Optionally provide a region as a hint. Doing this results will be more accurate.
  • You will receive a callback when your search is completed. Results include name, URL, phone number, coordinate, address components such as administrative area, city, street name and so on.

Example

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 your search is finished 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:
            ()
        }
    }
}

Requirements

  • Swift 2.2
  • iPhone, iPad
  • iOS 8.0 or later

Installation

pod "MWPlaceSearch"

Author

Masahiro Watanabe, [email protected]

License

MWPlaceSearch is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MWPlaceSearch",
    "version": "0.1.0",
    "summary": "MWPlaceSearch is an easy-to-use MKLocalSearch wrapper written in Swift",
    "description": "Did you know Apple officially provides a limit-free place search API called MKLocalSearch ?nMWPlaceSearch is an easy-to-use MKLocalSearch library written in Swift.nn* Search with a natural query like 'Sushi Vancouver'n* Optionally provide a region as a hint. Doing this results will be more accurate.n* You will receive a callback when your search is completed. Results include name, URL, phone number, coordinate, address components such as administrative area, city, street name and so on.",
    "homepage": "https://github.com/mshrwtnb/MWPlaceSearch",
    "license": "MIT",
    "authors": {
        "Masahiro Watanabe": "[email protected]"
    },
    "source": {
        "git": "https://github.com/mshrwtnb/MWPlaceSearch.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "MWPlaceSearch/Classes/**/*",
    "frameworks": "MapKit"
}

Pin It on Pinterest

Share This