样式谷歌地图标记

时间:2017-10-27 03:41:52

标签: javascript html css google-maps google-maps-markers

我正在使用基础框架构建移动应用。我在谷歌地图上的样式标记有问题。我已经按照参考在谷歌上建立一个标记。但我不知道如何设置里面有按钮的标记。

第1张图片:这是我应该遵循的设计

Example design

第二张图片:这是我到目前为止所完成的输出 output

映射代码:

function initMap() {
    var myLatLng = {lat: 2.924793, lng: 101.651487};

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      center: myLatLng,
       styles: [
        {elementType: 'geometry', stylers: [{color: '#242633'}]},
        {elementType: 'labels.text.stroke', stylers: [{color: '#242f3e'}]},
        {elementType: 'labels.text.fill', stylers: [{color: '#B9D0DB'}]},
        {
          featureType: 'administrative.locality',
          elementType: 'labels.text.fill',
          stylers: [{color: '#B9D0DB'}]
        },
        {
          featureType: 'poi',
          elementType: 'labels.text.fill',
          stylers: [{color: '#B9D0DB'}]
        },
        {
          featureType: 'poi.park',
          elementType: 'geometry',
          stylers: [{color: '#263c3f'}]
        },
        {
          featureType: 'poi.park',
          elementType: 'labels.text.fill',
          stylers: [{color: '#6b9a76'}]
        },
        {
          featureType: 'road',
          elementType: 'geometry',
          stylers: [{color: '#33354F'}]
        },
        {
          featureType: 'road',
          elementType: 'geometry.stroke',
          stylers: [{color: '#212a37'}]
        },
        {
          featureType: 'road',
          elementType: 'labels.text.fill',
          stylers: [{color: '#00C4FF'}]
        },
        {
          featureType: 'road.highway',
          elementType: 'geometry',
          stylers: [{color: '#746855'}]
        },
        {
          featureType: 'road.highway',
          elementType: 'geometry.stroke',
          stylers: [{color: '#1f2835'}]
        },
        {
          featureType: 'road.highway',
          elementType: 'labels.text.fill',
          stylers: [{color: '#f3d19c'}]
        },
        {
          featureType: 'transit',
          elementType: 'geometry',
          stylers: [{color: '#2f3948'}]
        },
        {
          featureType: 'transit.station',
          elementType: 'labels.text.fill',
          stylers: [{color: '#d59563'}]
        },
        {
          featureType: 'water',
          elementType: 'geometry',
          stylers: [{color: '#17263c'}]
        },
        {
          featureType: 'water',
          elementType: 'labels.text.fill',
          stylers: [{color: '#515c6d'}]
        },
        {
          featureType: 'water',
          elementType: 'labels.text.stroke',
          stylers: [{color: '#17263c'}]
        }
      ]

    });

    var marker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      title: 'Location History',

    });
  }

1 个答案:

答案 0 :(得分:0)

 var image = 'img/icons/marker.svg';
    var marker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      title: 'Location History',
      icon: image,
      url: 'add_order.html',
    });

    google.maps.event.addListener(marker, 'click', function() {
    window.location.href = marker.url;
});