JavaScript   

Get latitude and longitude from Google places autocomplete

This short code snippet is about getting the latitude and longitude of the selected address from places autocomplete.
Note – Don’t forget to include the following script tag in your webpage before the given code snippet.

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=places"></script>
  function getPlace(){
    const input = document.getElementById("fieldID");
    const options = {
      //add options here if you want more customizations
    };
    const autocomplete = new google.maps.places.Autocomplete(input, options);
    google.maps.event.addListener(autocomplete, 'place_changed', function () {
      let place = autocomplete.getPlace();
      console.log(place.geometry.location.lat());
      console.log(place.geometry.location.lng());
    });
  }
  window.addEventListener('load', getPlace);
Need Professional Support for Your Website Problems?

Whether you're facing website issues or struggling with code implementation, our team is here to assist. Hire us to get your website back on track.

Hire Us

Got an idea? We'll turn it into reality.

Tell us what you're building, what's broken, or what numbers need to move. We'll come back within one business day with a short plan — no long decks, no sales calls without purpose.

Response time: First reply within 1 business day on 100% of messages.
Transparent scope: Fixed proposals with weekly check-ins & live task tracking.
Ship-ready builds: Every engagement leaves behind documented, transferable work.
Long-term partners: Ongoing retainers for support, SEO, ads, and content.