Google maps: place number in marker?

前端 未结 11 2179
感情败类
感情败类 2020-12-12 17:09

How can I display a number in the marker on a google map? I want to do server side clustering and I need to display how many points the cluster represents.

11条回答
  •  星月不相逢
    2020-12-12 18:01

    Latest google js API has google.maps.MarkerLabel object.

    So you can easily set text/styles for labels

    var mIcon = {
      path: google.maps.SymbolPath.CIRCLE,
      fillOpacity: 1,
      fillColor: '#fff',
      strokeOpacity: 1,
      strokeWeight: 1,
      strokeColor: '#333',
      scale: 12
    };
    
    var gMarker = new google.maps.Marker({
      map: gmap,
      position: latLng,
      title: 'Number 123',
      icon: mIcon,
      label: {color: '#000', fontSize: '12px', fontWeight: '600',
        text: '123'}
    });
    

    jsfiddle

提交回复
热议问题