How to change GMarker color in Google Maps?

Quite a simple request, but there seems to be no way to do this. I just want my GMarkers to be green, not red.

Do I need to create my own badges?

+3
source share
4 answers

The best way I've found is with the following scripts ...

labeledmarker.js

mapiconmaker.js

you will need the following code snippet:

var iconOptions = {};
iconOptions.width = 32;
iconOptions.height = 32;
iconOptions.primaryColor = "#66CC6600";
iconOptions.cornerColor = "#66CC6600";
iconOptions.strokeColor = "#000000FF";
var iconSeller = MapIconMaker.createMarkerIcon(iconOptions);

function createMarker(icon, point,html,label) 
{
    opts = 
    { 
        "icon": icon,
        "labelText": label,      
        "labelClass": "markerLabel",
        "labelOffset": new GSize(-4, -31)
    };
    var marker = new LabeledMarker(point, opts);
    GEvent.addListener(marker, "click", 
        function() 
        {
            marker.openInfoWindowHtml(html);
        });
    return marker;
}

Make sure you have a class in the stylesheet called markerLabelso that you can style the div containing the label. I pinched most of this code from the excellent econym tutorial site, where there are many clear code examples.

+1
source

This is the easiest way:

var greenIcon = new GIcon(G_DEFAULT_ICON);
greenIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png";
var markerOptions = { icon:greenIcon };

var marker = new GMarker(point, markerOptions);

- Google, .

MapIconMaker , .

+4

: > >

, . - , API . , , GSize, - .

G_DEFAULT_ICON. , , .

, . G_DEFAULT_ICON GIcon, , .image . .

0
source

I need a project to add gmarker to a map and get data from web services

0
source

Source: https://habr.com/ru/post/1730012/


All Articles