Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p>Autocomplete is a feature of the Places library in the Google Maps JavaScript API. Below is the exmaple which was done using AutocompleteService & twitter typeahead autocomplete library. With this approach you can customize the display of results for your needs. If user entered invalid address you can display your own custom message.</p>
<section>
<input type="text" class="typeahead" placeholder="Enter location"/>
<div id="container">&nbsp;</div>
</section>

<p>Autocomplete is a feature of the Places library in the Google Maps JavaScript API. Below is the exmaple which was done using Google Autocomplete. Advantage of this integration typeahead and places api integration will come by default. Cons are you cannot display your custom message if there are no results.</p>
<section>
    <input type="text" name="street-address-field" id="street-address-field" class="tt-hint"/>
</section>
              
            
!

CSS

              
                section{
  min-height: 150px;
}

.tt-suggestion{
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
}
              
            
!

JS

              
                $(function(){
           var searchInput = $(".typeahead");  
           var sessionToken = new google.maps.places.AutocompleteSessionToken();
        var service = new google.maps.places.AutocompleteService(); 
        var predictions, status;

        $(".typeahead").typeahead({
            highlight: true,
            minLength: 3,
            autoselect: true
            
        },
        {
      async: true,
      display: 'address',
      source: function(query, process, aProcess) {
            service.getPlacePredictions({
                input: query,
                sessionToken: sessionToken
            }, function(predictions, status){
                aProcess(formatAddress(predictions, status));
            });
            
      },
      templates:{
        empty: [
                '<div class="empty-message text-center" style="">',
                'No address available.<br/>',
                '</div>',
            ].join('\n'),
          suggestion: function(data){
              console.log(data);
              return ['<div data-place-id="'+data.placeId+'">'+data.address+'</div>'].join('\n');
          },
        footer: '<div style="text-align:right; padding-right: 10px;"><img src="https://cdn.doordash.com/static/img/consumer/share/powered_by_google_on_white_hdpi.png" style="height:18px;"/></div>'
      }
      
    });

    var formatAddress = function(predictions, status){
        console.log("Predictions", predictions);
        console.log("Status", status);
        var formatttedAddress = [];
        var placeObj = {};
        if (status === "OK"){
            predictions.forEach(function(prediction) {
                placeObj.address = prediction.description;
                placeObj.placeId = prediction.place_id;
                formatttedAddress.push(placeObj)
                placeObj = {};
            });
        }
        console.log("FormattedAddress", formatttedAddress);
        return formatttedAddress;
    }

    $(".typeahead").on('typeahead:selected typeahead:autocompleted', function(e, datum) {
        // this input is the input that needs the imdb_id value
        //alert(datum.placeId);
        var container = document.getElementById("container");
        var service = new google.maps.places.PlacesService(container);
        service.getDetails({
          placeId: datum.placeId
        },function(place,status){
            if (status === google.maps.places.PlacesServiceStatus.OK) {
              document.getElementById("container").innerHTML= "Lat :"+ place.geometry.location.lat() + "<br/>" + "Lan:" + place.geometry.location.lng()
                console.log("Lat", place.geometry.location.lat());
                console.log("Lan", place.geometry.location.lng());
            }
        }
        )
    }); 



  
  /* Google Places Autocomplete */
    var autocompleteFormField = document.getElementById('street-address-field');

    var autocomplete = new google.maps.places.Autocomplete((autocompleteFormField), {
        types: [`address`]
    });

})
              
            
!
999px

Console