hnkgoogleplacesautocomplete


Introduction

Welcome to the official documentation for HNKGooglePlacesAutocomplete! This library provides an easy-to-use wrapper around the Google Places Autocomplete API for iOS development.


Installation

Cocoapods

To install HNKGooglePlacesAutocomplete via Cocoapods, add the following line to your Podfile:

pod 'HNKGooglePlacesAutocomplete'

Manual installation

If you prefer to install the library manually, follow these steps:

1. Download the latest release from the GitHub repository.
2. Add the 'HNKGooglePlacesAutocomplete' folder to your Xcode project.
3. Ensure that the 'HNKGooglePlacesAutocomplete' folder is added to the project's target.


Usage

Importing the library

To begin using HNKGooglePlacesAutocomplete in your project, add the following import statement:

import HNKGooglePlacesAutocomplete

Searching for Places

To search for places using the Google Places Autocomplete API, use the following code:

let autocompleteRequest = HNKGooglePlacesAutocompleteRequest()
autocompleteRequest.query = "New York" // Specify the search query here

HNKGooglePlacesAutocomplete.shared.autocompleteQuery(autocompleteRequest) { (places: [HNKGooglePlacesAutocompletePlace]?, error: Error?) in
    if let error = error {
        print("Error occurred: \(error.localizedDescription)")
        return
    }
    
    // Handle the places found in the 'places' array
}

Place Details

To retrieve detailed information for a specific place, use the following code:

let placeRequest = HNKGooglePlacesAutocompletePlaceRequest()
placeRequest.placeID = "PLACE_ID_HERE" // Specify the place ID here

HNKGooglePlacesAutocomplete.shared.lookUpPlace(placeRequest) { (place: HNKGooglePlacesAutocompletePlace?, error: Error?) in
    if let error = error {
        print("Error occurred: \(error.localizedDescription)")
        return
    }
    
    // Access place details using 'place' object
    if let place = place {
        print("Place name: \(place.name)")
        print("Place formatted address: \(place.formattedAddress)")    
        // Add more code to handle other place details you may need
    }
}


Conclusion

Congratulations! You have successfully integrated HNKGooglePlacesAutocomplete into your iOS project. This documentation should serve as a guide to get you started with using the library’s features.

For more detailed information, please refer to the official GitHub repository.