How to personalize a Marker on Google Maps with CSS












-1















I have a google map on my html file and is working fine:)! Now I'm trying to personalize the Marker, I can change the img but I want also make it rounded with border-radius: 50%; and give it a border value too. Is that possible? right now I have the picture (squared) and I want to style it with css, is that even possible?



example



JAVASCRIPT



 function initMap() {
// This is the minimum zoom level that we'll allow
var minZoomLevel = 4;

var map = new google.maps.Map(document.getElementById('mapLayer'), {
zoom: minZoomLevel,
center: new google.maps.LatLng(38.50, -90.50),
streetViewControl: false,
mapTypeControl: false,
scaleControl: false,
gestureHandling: 'cooperative',
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
});

// Bounds for world
var strictBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-54, -137.50),
new google.maps.LatLng(81, 170.90));

// Listen for the dragend event
google.maps.event.addListener(map, 'dragend', function () {
if (strictBounds.contains(map.getCenter())) return;

// We're out of bounds - Move the map back within the bounds

var c = map.getCenter(),
x = c.lng(),
y = c.lat(),
maxX = strictBounds.getNorthEast().lng(),
maxY = strictBounds.getNorthEast().lat(),
minX = strictBounds.getSouthWest().lng(),
minY = strictBounds.getSouthWest().lat();

if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;

map.setCenter(new google.maps.LatLng(y, x));
});

// Limit the zoom level
google.maps.event.addListener(map, 'zoom_changed', function () {
if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
});









share|improve this question



























    -1















    I have a google map on my html file and is working fine:)! Now I'm trying to personalize the Marker, I can change the img but I want also make it rounded with border-radius: 50%; and give it a border value too. Is that possible? right now I have the picture (squared) and I want to style it with css, is that even possible?



    example



    JAVASCRIPT



     function initMap() {
    // This is the minimum zoom level that we'll allow
    var minZoomLevel = 4;

    var map = new google.maps.Map(document.getElementById('mapLayer'), {
    zoom: minZoomLevel,
    center: new google.maps.LatLng(38.50, -90.50),
    streetViewControl: false,
    mapTypeControl: false,
    scaleControl: false,
    gestureHandling: 'cooperative',
    scrollwheel: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    // Bounds for world
    var strictBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-54, -137.50),
    new google.maps.LatLng(81, 170.90));

    // Listen for the dragend event
    google.maps.event.addListener(map, 'dragend', function () {
    if (strictBounds.contains(map.getCenter())) return;

    // We're out of bounds - Move the map back within the bounds

    var c = map.getCenter(),
    x = c.lng(),
    y = c.lat(),
    maxX = strictBounds.getNorthEast().lng(),
    maxY = strictBounds.getNorthEast().lat(),
    minX = strictBounds.getSouthWest().lng(),
    minY = strictBounds.getSouthWest().lat();

    if (x < minX) x = minX;
    if (x > maxX) x = maxX;
    if (y < minY) y = minY;
    if (y > maxY) y = maxY;

    map.setCenter(new google.maps.LatLng(y, x));
    });

    // Limit the zoom level
    google.maps.event.addListener(map, 'zoom_changed', function () {
    if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
    });









    share|improve this question

























      -1












      -1








      -1








      I have a google map on my html file and is working fine:)! Now I'm trying to personalize the Marker, I can change the img but I want also make it rounded with border-radius: 50%; and give it a border value too. Is that possible? right now I have the picture (squared) and I want to style it with css, is that even possible?



      example



      JAVASCRIPT



       function initMap() {
      // This is the minimum zoom level that we'll allow
      var minZoomLevel = 4;

      var map = new google.maps.Map(document.getElementById('mapLayer'), {
      zoom: minZoomLevel,
      center: new google.maps.LatLng(38.50, -90.50),
      streetViewControl: false,
      mapTypeControl: false,
      scaleControl: false,
      gestureHandling: 'cooperative',
      scrollwheel: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
      });

      // Bounds for world
      var strictBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(-54, -137.50),
      new google.maps.LatLng(81, 170.90));

      // Listen for the dragend event
      google.maps.event.addListener(map, 'dragend', function () {
      if (strictBounds.contains(map.getCenter())) return;

      // We're out of bounds - Move the map back within the bounds

      var c = map.getCenter(),
      x = c.lng(),
      y = c.lat(),
      maxX = strictBounds.getNorthEast().lng(),
      maxY = strictBounds.getNorthEast().lat(),
      minX = strictBounds.getSouthWest().lng(),
      minY = strictBounds.getSouthWest().lat();

      if (x < minX) x = minX;
      if (x > maxX) x = maxX;
      if (y < minY) y = minY;
      if (y > maxY) y = maxY;

      map.setCenter(new google.maps.LatLng(y, x));
      });

      // Limit the zoom level
      google.maps.event.addListener(map, 'zoom_changed', function () {
      if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
      });









      share|improve this question














      I have a google map on my html file and is working fine:)! Now I'm trying to personalize the Marker, I can change the img but I want also make it rounded with border-radius: 50%; and give it a border value too. Is that possible? right now I have the picture (squared) and I want to style it with css, is that even possible?



      example



      JAVASCRIPT



       function initMap() {
      // This is the minimum zoom level that we'll allow
      var minZoomLevel = 4;

      var map = new google.maps.Map(document.getElementById('mapLayer'), {
      zoom: minZoomLevel,
      center: new google.maps.LatLng(38.50, -90.50),
      streetViewControl: false,
      mapTypeControl: false,
      scaleControl: false,
      gestureHandling: 'cooperative',
      scrollwheel: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
      });

      // Bounds for world
      var strictBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(-54, -137.50),
      new google.maps.LatLng(81, 170.90));

      // Listen for the dragend event
      google.maps.event.addListener(map, 'dragend', function () {
      if (strictBounds.contains(map.getCenter())) return;

      // We're out of bounds - Move the map back within the bounds

      var c = map.getCenter(),
      x = c.lng(),
      y = c.lat(),
      maxX = strictBounds.getNorthEast().lng(),
      maxY = strictBounds.getNorthEast().lat(),
      minX = strictBounds.getSouthWest().lng(),
      minY = strictBounds.getSouthWest().lat();

      if (x < minX) x = minX;
      if (x > maxX) x = maxX;
      if (y < minY) y = minY;
      if (y > maxY) y = maxY;

      map.setCenter(new google.maps.LatLng(y, x));
      });

      // Limit the zoom level
      google.maps.event.addListener(map, 'zoom_changed', function () {
      if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
      });






      javascript css google-maps






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 28 '18 at 21:59









      EugenioEugenio

      309112




      309112
























          1 Answer
          1






          active

          oldest

          votes


















          0














          There are many possibilities to achieve that:



          Use RichMarker for Google Maps v3



          https://stackoverflow.com/a/25048625/1087623



          Use CSS selector img src if you know the URL of the image to apply style



          https://stackoverflow.com/a/25371006/1087623



          Add a class CSS to the marker Layer DIV then apply CSS style:



          http://bl.ocks.org/amenadiel/f4e5bd78b214ff081254






          share|improve this answer
























          • thanks @Taha Azzabi very useful! I've tried with RichMarker, modified the file directly on Jsfiddle, then when I used on my own file didn't work. I also implemented the RichMarker.js file and the other external link and nothing. I like the 2nd one but, if I have several images? not sure why the Img has the link to the image repeated on the css? what If I want to create several markers? I should also repeat the css styles for all of them? (border-radius, border, shadow, etc)

            – Eugenio
            Nov 28 '18 at 23:02












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528753%2fhow-to-personalize-a-marker-on-google-maps-with-css%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          There are many possibilities to achieve that:



          Use RichMarker for Google Maps v3



          https://stackoverflow.com/a/25048625/1087623



          Use CSS selector img src if you know the URL of the image to apply style



          https://stackoverflow.com/a/25371006/1087623



          Add a class CSS to the marker Layer DIV then apply CSS style:



          http://bl.ocks.org/amenadiel/f4e5bd78b214ff081254






          share|improve this answer
























          • thanks @Taha Azzabi very useful! I've tried with RichMarker, modified the file directly on Jsfiddle, then when I used on my own file didn't work. I also implemented the RichMarker.js file and the other external link and nothing. I like the 2nd one but, if I have several images? not sure why the Img has the link to the image repeated on the css? what If I want to create several markers? I should also repeat the css styles for all of them? (border-radius, border, shadow, etc)

            – Eugenio
            Nov 28 '18 at 23:02
















          0














          There are many possibilities to achieve that:



          Use RichMarker for Google Maps v3



          https://stackoverflow.com/a/25048625/1087623



          Use CSS selector img src if you know the URL of the image to apply style



          https://stackoverflow.com/a/25371006/1087623



          Add a class CSS to the marker Layer DIV then apply CSS style:



          http://bl.ocks.org/amenadiel/f4e5bd78b214ff081254






          share|improve this answer
























          • thanks @Taha Azzabi very useful! I've tried with RichMarker, modified the file directly on Jsfiddle, then when I used on my own file didn't work. I also implemented the RichMarker.js file and the other external link and nothing. I like the 2nd one but, if I have several images? not sure why the Img has the link to the image repeated on the css? what If I want to create several markers? I should also repeat the css styles for all of them? (border-radius, border, shadow, etc)

            – Eugenio
            Nov 28 '18 at 23:02














          0












          0








          0







          There are many possibilities to achieve that:



          Use RichMarker for Google Maps v3



          https://stackoverflow.com/a/25048625/1087623



          Use CSS selector img src if you know the URL of the image to apply style



          https://stackoverflow.com/a/25371006/1087623



          Add a class CSS to the marker Layer DIV then apply CSS style:



          http://bl.ocks.org/amenadiel/f4e5bd78b214ff081254






          share|improve this answer













          There are many possibilities to achieve that:



          Use RichMarker for Google Maps v3



          https://stackoverflow.com/a/25048625/1087623



          Use CSS selector img src if you know the URL of the image to apply style



          https://stackoverflow.com/a/25371006/1087623



          Add a class CSS to the marker Layer DIV then apply CSS style:



          http://bl.ocks.org/amenadiel/f4e5bd78b214ff081254







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 22:12









          Taha AzzabiTaha Azzabi

          704616




          704616













          • thanks @Taha Azzabi very useful! I've tried with RichMarker, modified the file directly on Jsfiddle, then when I used on my own file didn't work. I also implemented the RichMarker.js file and the other external link and nothing. I like the 2nd one but, if I have several images? not sure why the Img has the link to the image repeated on the css? what If I want to create several markers? I should also repeat the css styles for all of them? (border-radius, border, shadow, etc)

            – Eugenio
            Nov 28 '18 at 23:02



















          • thanks @Taha Azzabi very useful! I've tried with RichMarker, modified the file directly on Jsfiddle, then when I used on my own file didn't work. I also implemented the RichMarker.js file and the other external link and nothing. I like the 2nd one but, if I have several images? not sure why the Img has the link to the image repeated on the css? what If I want to create several markers? I should also repeat the css styles for all of them? (border-radius, border, shadow, etc)

            – Eugenio
            Nov 28 '18 at 23:02

















          thanks @Taha Azzabi very useful! I've tried with RichMarker, modified the file directly on Jsfiddle, then when I used on my own file didn't work. I also implemented the RichMarker.js file and the other external link and nothing. I like the 2nd one but, if I have several images? not sure why the Img has the link to the image repeated on the css? what If I want to create several markers? I should also repeat the css styles for all of them? (border-radius, border, shadow, etc)

          – Eugenio
          Nov 28 '18 at 23:02





          thanks @Taha Azzabi very useful! I've tried with RichMarker, modified the file directly on Jsfiddle, then when I used on my own file didn't work. I also implemented the RichMarker.js file and the other external link and nothing. I like the 2nd one but, if I have several images? not sure why the Img has the link to the image repeated on the css? what If I want to create several markers? I should also repeat the css styles for all of them? (border-radius, border, shadow, etc)

          – Eugenio
          Nov 28 '18 at 23:02




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528753%2fhow-to-personalize-a-marker-on-google-maps-with-css%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Futebolista

          Jornalista