Check out example codes for "input adresse ville automatique". It will help you in understanding the concepts better.

Code Example 1

"use strict";

// This example requires the Drawing library. Include the libraries=drawing
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBIwzALxUPNbatRBj3Xi1Uhp0fFzwWNBkE&libraries=drawing">

  function initializeAutocomplete(id) {
        var element = document.getElementById(id);
        if (element) {
         var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] });
         google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChanged);
        }
      }

      // Injecte les données dans les champs du formulaire lorsqu'une adresse est sélectionnée
      function onPlaceChanged() {
        var place = this.getPlace();

        for (var i in place.address_components) {
          var component = place.address_components[i];
          for (var j in component.types) {
            var type_element = document.getElementById(component.types[j]);
            if (type_element) {
              type_element.value = component.long_name;
            }
          }
        }

        var longitude = document.getElementById("longitude");
        var latitude = document.getElementById("latitude");
        longitude.value = place.geometry.location.lng();
        latitude.value = place.geometry.location.lat();
      }

      // Initialisation du champs autocomplete
      google.maps.event.addDomListener(window, 'load', function() {
        initializeAutocomplete('user_input_autocomplete_address');
      });

Code Example 2

<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=votre_cle_api" type="text/javascript">

Learn ReactJs, React Native from akashmittal.com