Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Settings google places fetch

 Hi Guys, 

 

I am writing my first fitbit app and I hit a snag. i would like to fetch an autocomplete list of adresses based on the users input. F.e. when typing new Y, it should show a list of addresses acquired by the api. 

 

Now I have this 

 

function findAddress(value) {
  console.log(value);
  
  const url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=' + value +'&key=SOMEKEYHERE';
  console.log(url);
  fetch(url, {
    method: "GET",
    mode: 'no-cors'
  }).then(function(res) {
    console.log(JSON.stringify(res.json()));
  });
}

function SettingsView(props) {
  console.dir(JSON.stringify(props));
  
  return (
    <Page>
      <Section
        title={<Text bold align="left">Settings</Text>}>
        <Text bold align="left">Address 1</Text>
        <TextInput
        title="Add List Item"
        label="Set Address"
        placeholder="Type something"
        action="Add Item"
        onAutocomplete={(value) => {
          findAddress(value);
        }}
        />

Now the first problem is that the res.json is empty, but if I call it in the browser it returns places like intended.

 

The second problem -> how can i return the autocomplete list to the TextInput? Does it work with promises?

 

 

I hope you can help.

 

Thanks,

Nick

Best Answer
1 REPLY 1

If I remove the 'mode: 'no-cors'' it returns a cors error. 

Best Answer
0 Votes