
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
google-places-autocomplete-service
Advanced tools
A simple factory using google places API to fetch predictions for places and get place details.
A simple factory using google places API to fetch predictions for places and get place details.
npm i -S google-places-autocomplete-service
Then add the Google Places API script to your page:
First add the dependency to your app:
import googlePlacesService from 'google-places-autocomplete-service';
Then initialize the service:
this.googlePlaces = googlePlacesService(options);
Then get predictions:
this.googlePlaces.getPredictions('example text', callback);
Then get place info:
this.googlePlaces.getPlace(predictionObject, callback);
And that's it.
The service accepts some options on initialization, for example:
this.googlePlaces = googlePlacesService({
type: 'geocode',
filterByCountry: 'US',
outputPlaceTypes: [
'postalCode',
'locality',
'administrativeAreaLevel1',
'country'
],
searchStrategies: [
'searchByPlaceId'
]
});
This option will be used in getPredictions
to filter predictions results - if none is passed geocode
will be used as a default.
This option will be used in getPredictions
to restrict the predictions results to a country.
Accepts uppercase ISO Alpha-2 country code - if none is passed then it will output global predictions.
This option will be used in getPlace
to make sure it will return a place with those place info types included.
This option will be used in getPlace
and will search for the specified place with the strategies passed - if none is passed then it will use all the strategies needed.
longitude
and latitude
are optional, but required if use only searchWithGeocoder
and nothing else.getPredictions(input, callback, regex)
Retrieves place autocomplete predictions based on the supplied arguments.
Return value: None
input
: string - The user entered input string.callback
: function - What to do with the results i.e: (predictions) => console.log(predictions)
.regex
: regexp - (optional) A regex to filter out predictions.The predictions object passing to the callback, is an object of placeIds as keys and the corresponding info of the prediction. Like that:
{
ChIJOwg_06VPwokRYv534QaPC8g: {
body: "New York, NY, United States"
terms: [
"New York",
"NY",
"United States"
],
type: "locality"
},
...
}
getPlace(prediction, callback)
Retrieves details about the place.
Return value: None
prediction
: object - the prediction :)
placeId
: string - the prediction's place ID.type
: string - prediction's first of types.terms
: array - prediction's string tokens.body
: string - prediction's body.callback
: function - What to do with the result i.e: (placeInfo) => console.log(placeInfo)
.The placeInfo passing to the callback, is an object with place's info like coords, prediction terms that couldn't find, status and of course all the place types that could find. For example:
{
coords: "40.6781784, -73.9441579",
sublocality: "Brooklyn",
locality: "New York",
administrativeAreaLevel1: "New York",
administrativeAreaLevel1Code: "NY",
country: "United States",
notValid: [],
status: "SUCCESS"
}
Create a ticket here
Issue a pull request.
FAQs
A simple factory using google places API to fetch predictions for places and get place details.
The npm package google-places-autocomplete-service receives a total of 1 weekly downloads. As such, google-places-autocomplete-service popularity was classified as not popular.
We found that google-places-autocomplete-service demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.