Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font Awesome icon as marker in Google Maps API V3

I want to use a font awesome icon as Google Maps marker. Here is my code:

function addMarker(marker) {    
    marker1 = new google.maps.Marker({ 
    position: new google.maps.LatLng(obj.geo_lat,obj.geo_lng),
    category: obj.status,
    map: map,
    icon: // Font Awesome icon here
});

I've looked at this question, but unfortunately this is not working properly for me. I was wondering if there's another way to do this.

like image 971
mishad050 Avatar asked Mar 12 '23 13:03

mishad050


2 Answers

Yes, there is. You can use RichMarker

Example:

function addMarker(marker) {    
        marker1 = new RichMarker({ 
            position: new google.maps.LatLng(obj.geo_lat,obj.geo_lng),
            category: obj.status,
            map: map,   
            draggable: false,
            flat:true,
            anchor: RichMarkerPosition.MIDDLE,
            content: '<i class="fa fa-map-marker fa-2x"></i>'
        });
}
like image 70
disprog Avatar answered Mar 19 '23 18:03

disprog


Another possible solution is this (without use of other external libraries):

marker1 = new google.maps.Marker({
    position: new google.maps.LatLng(obj.geo_lat,obj.geo_lng),
    map: map,
    label: {
        fontFamily: 'Fontawesome',
        text: '\uf192', //code for font-awesome icon
        fontSize: '15px',
        color: 'red'
    },
    icon: {
        path: google.maps.SymbolPath.CIRCLE, //or any others
        scale: 0
    }
});
like image 27
David71 Avatar answered Mar 19 '23 20:03

David71