jpowers / node-google-places Goto Github PK
View Code? Open in Web Editor NEWA Google Places lib for node.js
A Google Places lib for node.js
The reference field was deprecated on June 24 and replaced with place_id, so this module will stop working in about 9 months.
I'm happy to submit a pull request but I noticed there's an unmerged PR from June -- I wanted to see if you're still maintaining this module before I started work on it.
Thanks for putting together this module, Jay!
The npmjs readme says npm install node-google-places
when the package name is google-places
I loved this module . Would love to add more examples with illustrations . Example with detailed procedure to add API keys from google API console to developing full fledged applications using the module and add them to the example collection . If that sounds cool ill be sending pull requests to repo.
places.search doesn't include a location object. lol, what is this library?
This module has not been updated in a long time.
@jpowers are you accepting PRs?
I encountered this error with yarn
yarn install v1.3.2
[1/5] ๐ Validating package.json...
[2/5] ๐ Resolving packages...
Couldn't find any versions for "0" that matches "underscore"
? Please choose a version of "0" from this list: (Use arrow keys)
Which failed my CI and it seems it's because of the way dependencies are specified in this module (simple array, no versions).
For those of you, who might stumble on this problem, you can use a fork, such as this. Just do
yarn add https://github.com/BuildingConnected/node-google-places
And that should fix it up.
The downside is having a privately @ scoped dependency, so it's better to merge it in the main branch.
According to the Google Places docs, filtered types should be delimited by '|' not ','
I try your example of autocomplete and it get me the response in console , but i don't understand how add this response to my field .
$ ./google
search: []
/Users/user/projects/weed.uy/google:11
places.details({reference: response.results[0].reference}, function(err, res
^
TypeError: Cannot read property 'reference' of undefined
at /Users/user/projects/weed.uy/google:11:49
at IncomingMessage.<anonymous> (/Users/user/projects/weed.uy/node_modules/google-places/lib/google-places.js:82:11)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:910:16
at process._tickCallback (node.js:415:13)```
Trying to call places.autocomplete from a browser app (vue.js). Sorry if this turns out to be a question rather than an issue,.
Here's the code:
import Multiselect from 'vue-multiselect';
import debounce from 'lodash/debounce';
import cloneDeep from 'lodash/cloneDeep'
var GooglePlacesAPI = require('google-places');
var placeApi;
var vm;
module.exports = {
name: "GooglePlaces",
components: {
Multiselect
},
props: {
prop_id: String,
value: Object
},
data: function () {
return {
places: [],
selectedPlace: {},
isLoading: false,
resultCount: 0,
resultIndex: 0
};
},
created: function () {
vm = this;
placeApi = new GooglePlacesAPI('xxx'); //todo restrict
if (typeof vm.value === 'undefined') { return; }
vm.$set(vm, 'selectedPlace', cloneDeep(vm.value));
},
methods: {
googlePlaceSearch: debounce(searchString => {
if (searchString.length < 3) {
return;
}
vm.isLoading = true;
vm.resultCount = 0;
placeApi.autocomplete({ input: searchString, types: "(Regions)"}, vm.googlePlaceCallback);
}, 500),
googlePlaceCallback: function (err, response) {
if (err) {
console.log(err);
}
else {
places = [];
console.log("autocomplete: ", response.predictions);
vm.getPlaces(err, response);
}
},
getPlaces: function (err, response) {
for (var index in response.predictions) {
placesApi.details({ reference: response.predictions[index] }, vm.addPlace);
}
},
addPlace: function (err, response) {
if (err) {
console.log(err);
}
else {
places.push(response.result);
}
if (resultCount === resultIndex + 1) {
vm.isLoading = false;
vm.resultIndex = 0;
return;
}
vm.resultIndex++;
},
limitText: function (count) {
return `and ${count} other places`
},
placeChanged: function (newValue, id) {
//vm.$set(vm, 'selectedPlace', newValue); //handled by v-model
vm.$emit('input', newValue, id); //return as event per unidirectional data flow
},
}
};
Chrome is complaining:
Fetch API cannot load https://maps.googleapis.com/maps/api/place/autocomplete/json?input=vermont&types=(Regions)&language=en&sensor=false&key=xxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I'm not really sure what the underlying issue is. I'm on node 0.10.40 and while the tests pass, I always get {'status_code': 500, 'status_text': 'JSON Parse Failed'}
as a response for the autocomplete
endpoint. After digging in, it's because /
is being fetched, not the autocomplete endpoint and Google returns a 404.
I have a hunch the issue is with different versions of packages. There's no specific versions specified in the package.json
so installing it now or in the future could affect the module's behavior.
We would love to use the module if it is still maintained. Currently even the example provided fails -- are there plans to revive the project?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.