Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ add another resource


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


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.


Save Automatically?

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.


                <script src=";sensor=false&amp;libraries=places"></script>

<form action="javascript:void(0);" name="search" id="search-form">
  <input type="text" name="location" class="textbox" id="js-search-input" value="" />

<div id="google-map"></div>


                #google-map {         
    margin: 0 auto;      
    width: 600px;   
		height: 600px;   

input {
	width: 100%;
	max-width: 600px;
	margin: 20px auto;


                $(function() {
	function autocompleteWithEnter(map) {
		// search input
		const searchInput = document.getElementById("js-search-input");
		// options
		const options = {};
		// Google Maps Autocomplete Method
		const autocomplete = new google.maps.places.Autocomplete(

		// Store markers in array ready for clearing on update
		let markersArray = [];

		// Has user pressed the down key to navigate autocomplete options?
		let hasDownBeenPressed = false;

		// Default listener outside to stop nested loop returning odd results
		searchInput.addEventListener("keydown", e => {
			if (e.keyCode === 40) {
				hasDownBeenPressed = true;

		// GoogleMaps API custom eventlistener method
		google.maps.event.addDomListener(searchInput, "keydown", e => {
			// Maps API e.stopPropagation();
			e.cancelBubble = true;

			// If enter key, or tab key
			if (e.keyCode === 13 || e.keyCode === 9) {
				// If user isn't navigating using arrows and this hasn't ran yet
				if (!hasDownBeenPressed && !e.hasRanOnce) {
					google.maps.event.trigger(, "keydown", {
						keyCode: 40,
						hasRanOnce: true

		// place_changed GoogleMaps listener when we do submit
		google.maps.event.addListener(autocomplete, "place_changed", function() {
			// Get the place info from the autocomplete Api
			const place = autocomplete.getPlace();

			//If we can find the place lets go to it
			if (typeof place.address_components !== "undefined") {
				// reset hasDownBeenPressed in case they don't unfocus
				hasDownBeenPressed = false;

				// Get returned location
				const returnedCoords = new google.maps.LatLng(,
				const userLocation = {
				lng: place.geometry.location.lng()

				// add a marker
				new google.maps.Marker({
					position: returnedCoords,
					map: map

				// Focus map on new location
				getRoute(map, userLocation);

		function getRoute(map, coords) {
			const directionsDisplay = new google.maps.DirectionsRenderer({
			map: map,
			suppressMarkers: true,
			preserveViewport: false,
			polylineOptions: {
				strokeWeight: 4,
				strokeColor: '#e30613',
		const directionsService = new google.maps.DirectionsService();

			// Directions request object packet for the directionsService
			const request = {
				origin: coords,
				travelMode: google.maps.DirectionsTravelMode.DRIVING

			// Send the directionsService our request and wait for a response while checking the status of it
			directionsService.route(request, (response, status) => {
				// If the service is loaded properly and returning a response, update the route on our map
				if (status === google.maps.DirectionsStatus.OK) {
				} else {
					// Give us an error if the service isn't responding

		// Clear the input on focus, reset hasDownBeenPressed
		searchInput.addEventListener("focus", () => {
			hasDownBeenPressed = false;
			searchInput.value = "";

	// Default map init
	function initialize() {
		let latitude = 51.509865;
		let longitude = -0.118092;
		let center = new google.maps.LatLng(latitude, longitude);
		const mapOptions = {
			center: center,
			zoom: 10,
			mapTypeId: google.maps.MapTypeId.ROADMAP

		const map = new google.maps.Map(