Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Bootstrap Glyphicon as a Google Maps Marker

Struggling for this since a long time. I want to use Bootstrap glyphicon as a google map marker image. Below is my javascript code for google maps marker :

var image = {
    src: '<i class="glyphicon glyphicon-move"></i>',       
    size: new google.maps.Size(24, 24), 
    origin: new google.maps.Point(0,0),   
    anchor: new google.maps.Point(12,12)
    };
var marker = new google.maps.Marker({
        draggable: true,          
        icon: image,   
        title: 'Drag to move to new location',
        raiseOnDrag: false
    });      

If anyone can guide me with a example?

like image 576
idrisjafer Avatar asked Nov 11 '22 07:11

idrisjafer


1 Answers

Firstly, you will need the Glyphicons as vectors which you can purchase here: http://glyphicons.com/

With the Javascript API version 3, you can use an SVG path as described in the documentation here:

https://developers.google.com/maps/documentation/javascript/symbols#add_to_marker

The Google example code is thus:

// This example uses SVG path notation to add a vector-based symbol
// as the icon for a marker. The resulting icon is a star-shaped symbol
// with a pale yellow fill and a thick yellow border.

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {lat: -25.363882, lng: 131.044922}
  });

  var goldStar = {
    path: 'M 125,5 155,90 245,90 175,145 200,230 125,180 50,230 75,145 5,90 95,90 z',
    fillColor: 'yellow',
    fillOpacity: 0.8,
    scale: 1,
    strokeColor: 'gold',
    strokeWeight: 14
  };

  var marker = new google.maps.Marker({
    position: map.getCenter(),
    icon: goldStar,
    map: map
  });
}
like image 193
Alexander Holsgrove Avatar answered Nov 15 '22 04:11

Alexander Holsgrove