D
D
Dmitry2017-04-27 02:49:35
JavaScript
Dmitry, 2017-04-27 02:49:35

How to customize google map marker?

There is a script:

var geocoder;
var map;
var query = new Array('Набережные Челны, ул. Ш. Усманова 56а', 'Челябинск, ул. Кирова, д. 86');
var idArr = new Array('mp0','mp1');

function initialize() {
  geocoder = new google.maps.Geocoder();
  var mapOptions = {
    zoom: 15
  }
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  codeAddress();
}
 
function codeAddress() {
    for (var i = 0; i < query.length; i++) {
        var address = query[i];
    
        geocoder.geocode({
                'address': address
            }, function(k) {
                return function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        var a = document.getElementById(idArr[k]);
                        a.onclick = function() {
                            map.setZoom(17);
                            map.setCenter(results[0].geometry.location);
                        }
                        map.setCenter(results[0].geometry.location);
            
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location
                        });
                    } else {
                        alert('Geocode was not successful for the following reason: ' + status);
                    }
                }
            }(i)
        );
    }
}

google.maps.event.addDomListener(window, 'load', initialize);

The standard marker is displayed. Wherever I didn’t insert the code for displaying a custom marker, it doesn’t work at all, then it outputs again as standard. Help. How to display a custom marker icon instead of the default one?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2017-04-27
@freeExec

How, how - how Google advises . In your example, there is nothing at all.
en.marnoto.com/2014/09/5-formas-de-personalizar-in...

A
Andrey Glukhovskoy, 2017-05-23
@surprise_motherfucker

https://mapstyle.withgoogle.com/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question