cordova-plugin-googleplace
A Cordova plugin to use the Google Places SDK.
NOTE: this is a preliminary version, as of now only iOS is supported and Android is in the making
Getting Started
This plugin allows to user the Google Places SDK from Cordova, for building autocomplete UIs for locations.
Installing
$ SHELL COMMAND TO INSTALL
$ cordova plugin add cordova-plugin-googleplaces --variable API_KEY_FOR_IOS="XXXX"
Usage
For more details you can generate the Javascript docs with yarn doc
:
$ yarn docyarn run v1.1.0$ docco www/GooglePlaces.jsdocco: www/GooglePlaces.js -> docs/GooglePlaces.html
currentPlace
You can call the currentPlace
method to find information on the current locatoin.
This method requires that the user has enabled geolocation in the app. To to so, use cordova-plugin-geolocation (or equivalent) before calling this method.
// Authorize access to the current position using cordova-plugin-geolocationnavigatorgeolocation;
autocompleteQuery
The autocompleteQuery(query, [bounds], [filter], success, failure)
method find candidates ("predictions") given an input
query string:
cordovapluginsGooglePlaces;
This method can take optional arguments:
-
bounds
defines a regions to limit the search to.It should be defined as a "coordinate region" object such as:
northEast:latitude: 1234longitude: 5667southWest:latitude: 1234longitude: 5667 -
filter
defines a filter to limit the results to a specific region.Such a filter is given by a filter type taken from the
GooglePlaces.AutocompleteFilterTypes
and an (optional) country:filter: googlepluginsGooglePlacesAutocompleteFilterTypesNoFiltercountry: "FR" // <= this is optionalSeveral values are available for the filter type:
AutocompleteFilterTypes.NoFilter
is an empty filter; all results are returned.AutocompleteFilterTypes.Geocode
returns only autocomplete results with a precise address. Use this type when you know the user is looking for a fully specified address.AutocompleteFilterTypes.Address
returns only places that are businesses.AutocompleteFilterTypes.Establishment
returns only places that are businesses.AutocompleteFilterTypes.Region
returns only places that match one of the following types:locality
,sublocality
,postal_code
,country
,administrative_area_level_1
,administrative_area_level_2
AutocompleteFilterTypes.City
returns only results matchinglocality
oradministrative_area_level_3
.
pickPlace
pickplace([bounds], success, [failure])
displays the native UI for picking a nearby place.
This method requires that the user has enabled geolocation in the app. To to so, use cordova-plugin-geolocation (or equivalent) before calling this method.
cordovapluginsGooglePlaces;
The optional bounds
argument is defined as explained above:
northEast: latitude: 1234 longitude: 5667 southWest: latitude: 1234 longitude: 5667
showPlaceAutocomplete
Displays the native UI for place autocompletion.
cordovapluginsGooglePlaces;
Contributing
Feel free to contribute anytime !
License
This project is licensed under the MIT License - see the LICENSE file for details
TODO
- Add Android support