Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

create custom markers for each location google maps v3

any one can help me solve this: im trying to put custom icon or markers for each of the locations, i serch all the web for the awnser and the google docs but with no luck... thanks in advance.

btw im using the infobox for customize not the info window

here it's the code:

                    β€œvar infobox = new InfoBox();

            function initialize() {
            var secheltLoc = new google.maps.LatLng(32.46, -114.76);

            var myMapOptions = {
            zoom: 14,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            center: secheltLoc,
            disableDefaultUI: !0,
            panControl: !1,
            zoomControl: !0,
            minZoom: 2,
            scrollwheel: true,
            zoomControlOptions: {
            style: google.maps.ZoomControlStyle.DEFAULT,
            position: google.maps.ControlPosition.LEFT_CENTER
            },
            mapTypeControl: !0,
            mapTypeControlOptions: {
            mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID],
            position: google.maps.ControlPosition.BOTTOM
            },
            addressControlOptions: {
            position: google.maps.ControlPosition.BOTTOM
            },
            streetViewControl: !1,
            styles: [{
            featureType: "poi",
            elementType: "labels",
            stylers: [{
            visibility: "off"
            }]
            }]
            };

            var map = new google.maps.Map(document.getElementById("map"), myMapOptions);
            google.maps.event.addListener(map, "click", function() {
            infobox.close();
            });

            var marker = createMarker(map, new google.maps.LatLng(32.47568191956827, -114.78429794311523), 
            "text");
            var marker = createMarker(map, new google.maps.LatLng(32.47741970524178, -114.78361129760742),
            "text");
            var marker = createMarker(map, new google.maps.LatLng(32.480804670595184, -114.77479219436646), 
            "text");
            }

            function createMarker(map, latlng, html) {
            var boxText = document.createElement("div");
            boxText.style.cssText = "line-height:20px; border: text-align:justify; none; margin-top: 6px; background: #2b2b33; color: white; padding: 20px;";
            boxText.innerHTML = html;

            var myOptions = {
            content: boxText,
            disableAutoPan: false,
            maxWidth: 0,
            pixelOffset: new google.maps.Size(-167, -10),
            zIndex: null,
            boxStyle: {
            background: "url('tipbox.gif') no-repeat",
            width: "275px"
            },
            closeBoxMargin: "-4px -8px -11px -11px",
            closeBoxURL: "img/close.png",
            infoBoxClearance: new google.maps.Size(1, 1),
            isHidden: false,
            pane: "floatPane",
            enableEventPropagation: false,
            };

            var marker = new google.maps.Marker({
            map: map,
            draggable: false,
            position: latlng,
            visible: true,
            icon:"icon.png",
            });

            google.maps.event.addListener(marker, 'click', function() {
            infobox.open(map, this);
            infobox.setOptions(myOptions);
            });

            return marker;
            }

2 Answers

Caroline Hagan
Caroline Hagan
12,612 Points

Hi manuel arvizu I've had to use multiple markers before and saved the code; hopefully you pick from this what you need:

Google Map : multiple markers, each diff

thanks :D