【问题标题】:Google Map Styles cannot finding Parking LotsGoogle Map Styles 找不到停车场
【发布时间】:2022-10-12 23:56:12
【问题描述】:

我正在使用 Maps Javascript API 并对其进行样式设置。地图加载正常,没有错误,并且设置了除一个以外的所有兴趣点的样式。我一直无法找到一种风格停车场(付费停车场/地下停车场/建筑物停车场/运动场停车场)的方式。

我已经使用了参考表中列出的几乎所有选项,并且无法使用能够使其工作的功能类型。我还使用 google map styler 创建了自定义地图样式,但没有一个要素类型选项会改变停车场样式。

这是我用来设置地图样式的代码...

const styles = {
          default: [],
          hide: [
                {
                featureType: "all",
                elementType: "labels.text.fill",
                stylers: [
                    {
                        "saturation": 100
                    },
                    {
                        "color": "#999999" /* e944e9 */
                    },
                    {
                        "lightness": 15
                    }
                ]
            },
            {
                featureType: "all",
                elementType: "labels.text.stroke",
                stylers: [
                    {
                        "visibility": "on"
                    },
                    {
                        "color": "#000000"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "all",
                elementType: "labels.icon",
                stylers: [
                    {
                        "visibility": "off"
                    }
                ]
            },
            {
                featureType: "administrative",
                elementType: "geometry.fill",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "poi.park",
                elementType: "geometry.fill",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "poi.school",
                elementType: "geometry.fill",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "poi.medical",
                elementType: "geometry.fill",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "administrative",
                elementType: "geometry.stroke",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 10
                    },
                    {
                        "weight": 1.2
                    }
                ]
            },
            {
                featureType: "administrative.neighborhood",
                elementType: "geometry.stroke",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 100
                    },
                    {
                        "weight": 1.2
                    }
                ]
            },
            {
                featureType: "poi.sports_complex",
                elementType: "geometry",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "landscape",
                elementType: "geometry",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "road.arterial",
                elementType: "geometry.fill",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            {
                featureType: "road.arterial",
                elementType: "geometry.stroke",
                stylers: [
                    {
                        "color": "#260f50"
                    },
                    {
                        "lightness": 0
                    }
                ]
            },
            
            {
                featureType: "poi",
                elementType: "geometry",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 21
                    }
                ]
            },
            {
                featureType: "poi",
                elementType: "geometry.fill",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 8
                    },
                    {
                        "weight": 1
                    }
                ]
            },
            {
                featureType: "poi",
                elementType: "geometry.stroke",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 8
                    },
                    {
                        "weight": 100
                    }
                ]
            },
            {
                featureType: "road.highway",
                elementType: "geometry.fill",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 8
                    }
                ]
            },
            {
                featureType: "road.highway",
                elementType: "geometry.stroke",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 8
                    },
                    {
                        "weight": 0.2
                    }
                ]
            },
            {
                featureType: "road.arterial",
                elementType: "geometry",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 8
                    }
                ]
            },
            {
                featureType: "road.local",
                elementType: "geometry",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 8
                    }
                ]
            },
            {
                featureType: "transit",
                elementType: "geometry",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 8
                    }
                ]
            },
            {
                featureType: "water",
                elementType: "geometry",
                stylers: [
                    {
                        "color": "#220a4b"
                    },
                    {
                        "lightness": 1
                    }
                ]
            },
            {
              featureType: "poi.business",
              stylers: [{ "visibility": "off" }],
            },
            {
              featureType: "poi.government",
              elementType: "labels.icon",
              stylers: [{ "visibility": "off" }],
            },
            {
              featureType: "poi.medical",
              elementType: "labels.icon",
              stylers: [{ "visibility": "off" }],
            },
            {
              featureType: "poi.place_of_worship",
              stylers: [{ "visibility": "off" }],
             },
            {
              featureType: "poi.park",
              elementType: "labels.icon",
              stylers: [{ "visibility": "off" }],
            },
            {
              featureType: "transit.station.bus",
              elementType: "labels.icon",
              stylers: [{ "visibility": "on" }],
            },
            {
              featureType: "transit.line",
              elementType: "labels.icon",
              stylers: [{ "visibility": "off" }],
            },
          ],
    

【问题讨论】:

  • 似乎没有一种方法可以针对停车进行造型(并非所有内容都可以直接针对)。一种选择是查询该地区停车场的场所服务,并使用您自己的自定义图标 (example fiddle (with default marker icons)) 显示这些服务,或者为要显示的停车场创建自己的数据。
  • 这是一个好主意。我已经开始创建自定义标记并将它们标记为停车位。谢谢你。

标签: api google-maps


【解决方案1】:

似乎没有一种方法可以针对停车进行造型(并非所有内容都可以直接针对)。

您可以尝试创建一个feature request。

另一种选择是查询该地区停车场的场所服务,并使用您自己的自定义图标显示这些服务,或者为您想要显示的停车区域创建您自己的数据。

proof of concept fiddle

代码sn-p:

let map;
let infowindow;

function initMap() {
  infowindow = new google.maps.InfoWindow();
  // Styles a map.
  map = new google.maps.Map(document.getElementById("map"), {
    center: {
      lat: 32.7169289,
      lng: -117.1657514
    },
    zoom: 16,
    styles: [{
        featureType: "all",
        elementType: "labels.text.fill",
        stylers: [{
            "saturation": 100
          },
          {
            "color": "#999999" /* e944e9 */
          },
          {
            "lightness": 15
          }
        ]
      },
      {
        featureType: "all",
        elementType: "labels.text.stroke",
        stylers: [{
            "visibility": "on"
          },
          {
            "color": "#000000"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "all",
        elementType: "labels.icon",
        stylers: [{
          "visibility": "off"
        }]
      },
      {
        featureType: "administrative",
        elementType: "geometry.fill",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "poi.park",
        elementType: "geometry.fill",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "poi.school",
        elementType: "geometry.fill",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "poi.medical",
        elementType: "geometry.fill",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "administrative",
        elementType: "geometry.stroke",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 10
          },
          {
            "weight": 1.2
          }
        ]
      },
      {
        featureType: "administrative.neighborhood",
        elementType: "geometry.stroke",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 100
          },
          {
            "weight": 1.2
          }
        ]
      },
      {
        featureType: "poi.sports_complex",
        elementType: "geometry",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "landscape",
        elementType: "geometry",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "road.arterial",
        elementType: "geometry.fill",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },
      {
        featureType: "road.arterial",
        elementType: "geometry.stroke",
        stylers: [{
            "color": "#260f50"
          },
          {
            "lightness": 0
          }
        ]
      },

      {
        featureType: "poi",
        elementType: "geometry",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 21
          }
        ]
      },
      {
        featureType: "poi",
        elementType: "geometry.fill",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 8
          },
          {
            "weight": 1
          }
        ]
      },
      {
        featureType: "poi",
        elementType: "geometry.stroke",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 8
          },
          {
            "weight": 100
          }
        ]
      },
      {
        featureType: "road.highway",
        elementType: "geometry.fill",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 8
          }
        ]
      },
      {
        featureType: "road.highway",
        elementType: "geometry.stroke",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 8
          },
          {
            "weight": 0.2
          }
        ]
      },
      {
        featureType: "road.arterial",
        elementType: "geometry",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 8
          }
        ]
      },
      {
        featureType: "road.local",
        elementType: "geometry",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 8
          }
        ]
      },
      {
        featureType: "transit",
        elementType: "geometry",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 8
          }
        ]
      },
      {
        featureType: "water",
        elementType: "geometry",
        stylers: [{
            "color": "#220a4b"
          },
          {
            "lightness": 1
          }
        ]
      },
      {
        featureType: "poi.business",
        stylers: [{
          "visibility": "off"
        }],
      },
      {
        featureType: "poi.government",
        elementType: "labels.icon",
        stylers: [{
          "visibility": "off"
        }],
      },
      {
        featureType: "poi.medical",
        elementType: "labels.icon",
        stylers: [{
          "visibility": "off"
        }],
      },
      {
        featureType: "poi.place_of_worship",
        stylers: [{
          "visibility": "off"
        }],
      },
      {
        featureType: "poi.park",
        elementType: "labels.icon",
        stylers: [{
          "visibility": "off"
        }],
      },
      {
        featureType: "transit.station.bus",
        elementType: "labels.icon",
        stylers: [{
          "visibility": "on"
        }],
      },
      {
        featureType: "transit.line",
        elementType: "labels.icon",
        stylers: [{
          "visibility": "off"
        }],
      },
    ],
  });

  service = new google.maps.places.PlacesService(map);
  var request = {
    location: map.getCenter(),
    keyword: "parking",
    radius: '1000',
    type: ['parking']
  };

  service.nearbySearch(request, callback);
}

function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    console.log("results=" + results.length + " status=" + status)
    for (var i = 0; i < results.length; i++) {
      console.log("[" + i + "] name=" + results[i].name + " location=" + results[i].geometry.location.toUrlValue(6));
      createMarker(results[i]);
    }
  }
}

function createMarker(place) {
  if (!place.geometry || !place.geometry.location) return;

  const marker = new google.maps.Marker({
    map,
    position: place.geometry.location,
    title: place.name,
    label: "P"
  });

  google.maps.event.addListener(marker, "click", () => {
    infowindow.setContent(place.name || "");
    infowindow.open(map, marker);
  });
}
window.initMap = initMap;
#map {
  height: 100%;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
<!DOCTYPE html>
<html>

<head>
  <title>Styled Maps - Night Mode</title>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
  <!-- jsFiddle will insert css and js -->
</head>

<body>
  <div id="map"></div>
  <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap&v=weekly&libraries=places" defer></script>
</body>

</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 2020-12-01
    • 2012-07-27
    相关资源
    最近更新 更多