Local Weather, help with the autocomplete city search api from google [CLOSED]

Hey Guys,

I am trying to make an autocomplete input city search from google api so the weather will also be displayed on the preferred city…
Here is my code so far, https://codepen.io/simongjetaj/pen/KXvrVM?editors=1010
Can someone guide me through the process?

Hey. The Google maps API actually has an autocomplete feature, so you won’t need to do that much. Create a new istance of the Google API autocomplete for your input like so:

let searchBox = new google.maps.places.Autocomplete(document.querySelector("#city-search"));

Then, listen to the input changes (it should be “place” and not “places”):

searchBox.addListener('place_changed', function() {
    let locale = searchBox.getPlace();
    console.log(locale)
    console.log(locale.geometry.location.lat(), locale.geometry.location.lng()) // Latitude and Longitude - if you need them
});
1 Like

@noyb Thanks man once again! :slightly_smiling_face:
Fixed!