css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!-- google font -->
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,700' rel='stylesheet' type='text/css'>

<!-- google map api -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCfLY6n_J3aoyyK8VXNfVBVL7_kzqrXzNQ" type="text/javascript"></script>

<h1>Google Maps Custom Marker Demo</h1>

<!-- START MAP --> 	
<div class="google-map">
	<div class="marker" data-lat="53.483144" data-lng="-2.233307">
		<span class="marker-title">
			<strong>The Arndale</strong>
		</span>
		<span>Market Street <br>Manchester <br> M4 3AQ</span>
	</div>	
	
	<div class="marker" data-lat="53.4842467" data-lng="-2.2432947">
		<span class="marker-title">
			<strong>intu Trafford Centre</strong>
		</span>
		<span>Manchester <br> M17 8AA</span>
	</div>
</div>
<!-- END MAP -->

<!-- IF USING ACF MAPS
<?php

  $location = get_field('map');

  if( !empty($location) ):
  ?>
  <div class="google-map">
  	<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
      <span class="marker-title">
        <strong>The Arndale</strong>
      </span>
      <span>Market Street <br>Manchester <br> M4 3AQ</span>
  	</div>
  </div>
  <?php endif; ?> 
-->
            
          
!
            
              //page styles
body {
    margin: 0 50px 50px;    
    font-family: 'Open Sans', sans-serif;
}

h1 {
    font-size: 40px;
    padding: 50px 0;
    text-align: center;
    font-weight: 700;
}

//map starts here
.google-map {
  height: 400px;
	margin: 0 auto;
}

.marker {
	display: none;
}

span {
	line-height: 1.5;
}

.marker-title {
	display: block;
	font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    color: #58595B;
    margin-bottom: 2px;
}
            
          
!
            
              // google map
	// This function will render a Google Map onto the selected jQuery element
	function render_map( $el ) {

		// var
		var $markers = $el.find('.marker');

		// vars
		var args = {
			//overlay
			scrollwheel : false,
			zoomControl	: true,
			streetViewControl: false,
			mapTypeControl: true,
			panControl: false,
			//options
			scrollwheel : false,
			zoom		: 14,
			center		: new google.maps.LatLng(0, 0),
			mapTypeId	: google.maps.MapTypeId.ROADMAP,
			//optional styles
			styles: [
				{
			        featureType: 'all',
			        stylers: [
			            { saturation: -100 }
			        ]
			    }
			]
		};

		// create map	        	
		var map = new google.maps.Map( $el[0], args);

		// add a markers reference
		map.markers = [];

		// add markers
		$markers.each(function(){

	    	add_marker( $(this), map );

		});

		// center map
		center_map( map );

	}

	//add_marker 
	//This function will add a marker to the selected Google Map

	var currentInfoWindow;

	function add_marker( $marker, map ) {

		// var
		var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
		
		//custom img
		var image = 'http://www.tnetnoc.com/public/ANS/Dynaflex/Images/HCL/SEO/St-Kilda-Guide/Icons/MarkerPurple.png'

		// create marker
		var marker = new google.maps.Marker({
			position	: latlng,
			map			: map,
			icon		: image
		});

		// add to array
		map.markers.push( marker );

		// if marker contains HTML, add it to an infoWindow
		if( $marker.html() )
		{
			// create info window
			var infowindow = new google.maps.InfoWindow({
				content		: $marker.html()
			});

			// show info window when marker is clicked   
			google.maps.event.addListener(marker, 'click', function() {
				
				infowindow.open(map, marker);
				
				//close all other infowindows
				if (currentInfoWindow && currentInfoWindow != infowindow) {
					currentInfoWindow.close();
				}
				
				currentInfoWindow = infowindow;
			});
			
			// close info window when map is clicked
			google.maps.event.addListener(map, 'click', function(event) {
				if (currentInfoWindow) {
					currentInfoWindow.close();
				}
			});
		}

	}

	//center_map
	//This function will center the map, showing all markers attached to this map

	function center_map( map ) {

		// vars
		var bounds = new google.maps.LatLngBounds();

		// loop through all markers and create bounds
		$.each( map.markers, function( i, marker ){

			var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );

			bounds.extend( latlng );

		});

		// only 1 marker?
		if( map.markers.length == 1 )
		{
			// set center of map
		    map.setCenter( bounds.getCenter() );
		    map.setZoom( 12 );
		}
		else
		{
			// fit to bounds
			map.fitBounds( bounds );
		}

	}

	//document ready
	//This function will render each map when the document is ready (page has loaded)
	$(document).ready(function(){
		$('.google-map').each(function(){
			render_map( $(this) );
		});
	});

	//if in tabs / accordion (hidden)
// 	$(document).ready(function(){
// 		$('.google-map').each(function(){
// 			var map = $(this);

// 			if ($(this).parents('.map').length) {
// 				$(this).parents('.map').children('.btn').on('click', function() {
// 					if (!map.hasClass('rendered')) {
// 						render_map(map);
// 						map.addClass('rendered');
// 					}
// 				});
// 			} else {
// 				render_map(map);
// 			}
// 		});
// 	});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console