0

quite new to Javascript and have been on this problem for ages. I am trying to use Google Maps Javascript API to validate an address in a form and I have no idea why it is not working. I have inserted the API reference. I am using Angular Material (if you were wondering about the md stuff)

HTML

<md-input-container>
    <input id="pac-input" class="controls" type="text" placeholder="Enter a location">
</md-input-container>

Javascript

function initMap() {
    var input = (document.getElementById('pac-input'));
    var autocomplete = new google.maps.places.Autocomplete(input);
};

I know the answer must be super easy but you would be helping me a lot!

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
  • 1
    What doesn't work? Any error? Do you actually call `initMap()` anywhere? – MrUpsidown Oct 21 '15 at 16:05
  • It doesn't autocomplete anything. To the second question - I guess I am not. – Nicholas Oct 21 '15 at 16:14
  • Your code seems to work fine! [fiddle](http://jsfiddle.net/GVdK6/81/) Just call the `initMap();` – Stergios Marias Oct 21 '15 at 16:17
  • Thanks Stergios - It's an Angular application and when I open the view itself, it works (and your fiddle does too) but it doesnt work in my index.html when I open it - Very strange! – Nicholas Oct 21 '15 at 16:32
  • Do you have any error in console? Perhaps `google is not defined`? – Stergios Marias Oct 21 '15 at 16:36
  • This is the error I get in Safari inspect TypeError: window.initMap is not a function. (In 'window.initMap()', 'window.initMap' is undefined) – Nicholas Oct 21 '15 at 16:37
  • @Nicholas you will find the solution at http://stackoverflow.com/questions/32496382/typeerror-window-initmap-is-not-a-function . I dont know angular but by reading the answers in the link i think error is with `callback function`. – Sandeep Feb 02 '16 at 18:03

0 Answers0