簡體   English   中英

我想使用谷歌創建郵政編碼的邊界 map api

[英]I want to create boundaries of a zipcode using google map api

我想使用 google map places api 創建郵政編碼的邊界,但無法找到邊界坐標。

當我在 maps.google.com 上搜索郵政編碼時,我注意到它顯示了該特定郵政編碼的虛線邊界。 如何使用谷歌服務實現這一目標?

如果郵政編碼在您所在的國家/地區可用(檢查覆蓋范圍),則可以使用 DDS( 數據驅動樣式)來完成。

請注意,此功能目前仍處於預覽(Pre-GA)階段。

下面是繪制意大利隨機郵政編碼邊界的示例( 10123 Torino, Italy )。

要重現,您需要在 Google Maps Platform 控制台中創建一個新的 map ID 和 map 樣式以及相應的要素圖層 select。 所有信息都在這里

 let map; let featureLayer; function initMap() { map = new google.maps.Map(document.getElementById("map"), { center: { lat: 45.064335, lng: 7.688176 }, zoom: 13, mapId: "8ec1ff859561face", // You need to create your own map ID }); featureLayer = map.getFeatureLayer("POSTAL_CODE"); // Define the styling options const featureStyleOptions = { strokeColor: "#00FF00", strokeOpacity: 1, strokeWeight: 1, fillColor: '#519400', fillOpacity: 1, }; // Apply the style to a single boundary. featureLayer.style = (options) => { if (options.feature.placeId == "ChIJ_7qz12VtiEcRcKS3k4DmBRw") { // Above Place ID is zipcode 10123 Torino, Italy return featureStyleOptions; } }; }
 #map { height: 180px; }
 <div id="map"></div> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap&v=beta" defer></script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM