CodeDezk
CodeDezk

Reputation: 1260

HTML google map add custom div as marker

I need to implement map and custom marker as shown here , here is the map implementation html http://jsfiddle.net/4a87k/ But no idea how to add custom css as marker.

<head>
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>

      function initMap() {
        var myLatLng = {lat: -25.363, lng: 131.044};

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 4,
          center: myLatLng
        });

        var marker = new google.maps.Marker({
          position: myLatLng,
          map: map,
        });
      }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?sensor=false&callback=initMap">
    </script>
  </body>

Upvotes: 0

Views: 3130

Answers (1)

Nathaniel Flick
Nathaniel Flick

Reputation: 2963

The documentation for customising markers is very good, find it here.

And a simple example is to link to a png file directly for the marker, but you can do more with this with Custom Markers in the api:

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {lat: -33, lng: 151}
  });
      var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png';
      var beachMarker = new google.maps.Marker({
        position: {lat: -33.890, lng: 151.274},
        map: map,
        icon: image
      });
    }

Upvotes: 2

Related Questions