2014-05-22 15 views
5

Lottando per questo da molto tempo. Voglio usare glyphicon di Bootstrap come immagine di un indicatore di mappa di Google. Di seguito è riportato il mio codice javascript per google maps marker:Usa Bootstrap Glyphicon come indicatore di Google Maps

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 
    });  

Se qualcuno può guidarmi con un esempio?

+0

Controllare il codice sorgente di questo http: // GMaps-campioni-v3. googlecode.com/svn/trunk/overlayview/custommarker.html maggiori dettagli qui https://groups.google.com/forum/#!topic/google-maps-js-api-v3/kO9O1wqYjwU –

+0

Sembra che tu non possa. Leggi https://productforums.google.com/forum/#!msg/maps/c3W8kbRzCaQ/o3IQG_6D6r4J –

+1

Puoi usare le etichette invece http://jsbin.com/zenem/1/edit dove puoi controllare l'indicatore con css –

risposta

1

In primo luogo, è necessario disporre dei Glyphicons come vettori che potete acquistare qui: http://glyphicons.com/

Con la JavaScript API versione 3, è possibile utilizzare un percorso SVG come descritto nella documentazione qui:

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

il codice di esempio di Google è quindi:

// 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 
    }); 
} 
Problemi correlati