gpt4 book ai didi

google-maps - 谷歌地图如何显示城市或区域轮廓

转载 作者:行者123 更新时间:2023-12-03 06:24:36 28 4
gpt4 key购买 nike

如何像以下网站一样显示地点或区域轮廓:[我输入一个区域,它显示该区域的清晰边界。]

enter image description here

Link

我在官方 map 文档中搜索了几个小时,但不知道这些网站如何显示区域边界。还查看了一些旧问题并阅读了它是不可能的。

最佳答案

根据我的搜索,目前 Maps API v3 中没有来自 Google 的选项,并且有一个 issue on the Google Maps API going back to 2008.有一些较旧的问题 - Add "Search Area" outline onto google maps resultGoogle has started highlighting search areas in Pink color. Is this feature available in Google Maps API 3?您可能会在这里找到一些更新的答案以及更新的信息,但这不是一个功能。

What you can do is draw shapes on your map - 但为此您需要拥有您所在区域边界的坐标。

现在,为了获得行政区域边界,您必须做一些工作:http://www.gadm.org/country(如果您幸运并且那里有足够的详细信息)。

在此网站上,您可以本地下载扩展名为 .kmz 的文件(有多种可用格式)。解压它,您将得到一个 .kml 文件,其中包含大多数行政区域(城市、村庄)。

  <?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="x" id="x">
<SimpleField name="ID_0" type="int"></SimpleField>
<SimpleField name="ISO" type="string"></SimpleField>
<SimpleField name="NAME_0" type="string"></SimpleField>
<SimpleField name="ID_1" type="string"></SimpleField>
<SimpleField name="NAME_1" type="string"></SimpleField>
<SimpleField name="ID_2" type="string"></SimpleField>
<SimpleField name="NAME_2" type="string"></SimpleField>
<SimpleField name="TYPE_2" type="string"></SimpleField>
<SimpleField name="ENGTYPE_2" type="string"></SimpleField>
<SimpleField name="NL_NAME_2" type="string"></SimpleField>
<SimpleField name="VARNAME_2" type="string"></SimpleField>
<SimpleField name="Shape_Length" type="float"></SimpleField>
<SimpleField name="Shape_Area" type="float"></SimpleField>
</Schema>
<Folder><name>x</name>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#x">
<SimpleData name="ID_0">186</SimpleData>
<SimpleData name="ISO">ROU</SimpleData>
<SimpleData name="NAME_0">Romania</SimpleData>
<SimpleData name="ID_1">1</SimpleData>
<SimpleData name="NAME_1">Alba</SimpleData>
<SimpleData name="ID_2">1</SimpleData>
<SimpleData name="NAME_2">Abrud</SimpleData>
<SimpleData name="TYPE_2">Comune</SimpleData>
<SimpleData name="ENGTYPE_2">Commune</SimpleData>
<SimpleData name="VARNAME_2">Oras Abrud</SimpleData>
<SimpleData name="Shape_Length">0.2792904164402</SimpleData>
<SimpleData name="Shape_Area">0.00302673357146115</SimpleData>
</SchemaData></ExtendedData>
<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>23.117561340332031,46.269237518310547 23.108898162841797,46.265365600585937 23.107486724853629,46.264305114746207 23.104681015014762,46.260105133056641 23.101633071899471,46.250000000000114 23.100803375244254,46.249053955078239 23.097520828247184,46.246582031250114 23.0965576171875,46.245487213134822 23.095674514770508,46.244930267334098 23.092174530029354,46.243438720703182 23.088010787963924,46.240383148193473 23.083366394043082,46.238204956054801 23.075212478637809,46.234935760498047 23.071325302123967,46.239696502685547 23.070602416992131,46.241668701171875 23.069700241088924,46.242824554443416 23.068435668945369,46.243541717529354 23.066627502441406,46.244037628173771 23.064964294433651,46.246234893798885 23.062850952148437,46.247486114501953 23.0626220703125,46.248153686523438 23.062761306762752,46.250873565673942 23.061862945556697,46.255172729492301 23.061449050903434,46.256267547607422 23.05998420715332,46.258060455322322 23.057676315307674,46.259838104248161 23.055141448974666,46.262714385986442 23.053401947021484,46.264244079589901 23.049621582031193,46.266674041748161 23.043565750122013,46.268516540527457 23.041521072387695,46.269458770751953 23.034791946411076,46.270542144775334 23.027051925659293,46.27105712890625 23.025453567504826,46.271255493164063 23.022710800170898,46.272083282470703 23.020351409912053,46.271331787109432 23.018688201904297,46.270687103271598 23.015596389770508,46.270793914794922 23.014116287231502,46.271579742431697 23.009817123413143,46.275333404541016 23.006668090820426,46.277061462402401 23.004106521606445,46.279254913330135 23.001775741577205,46.282882690429688 23.005559921264648,46.283077239990348 23.009967803955135,46.28415679931652 23.014947891235465,46.286224365234489 23.019996643066463,46.28900146484375 23.024263381958121,46.292709350586051 23.027633666992301,46.295299530029411 23.028041839599609,46.295692443847656 23.032444000244197,46.294342041015625 23.03491401672369,46.293315887451229 23.044847488403434,46.290401458740234 23.047790527343807,46.28928375244152 23.053009033203239,46.288627624511719 23.057231903076229,46.288341522216797 23.064565658569393,46.287548065185547 23.070388793945426,46.286254882812614 23.075139999389592,46.284847259521428 23.075983047485465,46.284801483154411 23.085800170898494,46.28253173828125 23.098115921020451,46.280982971191406 23.099718093872127,46.280590057373104 23.105833053588981,46.278388977050838 23.112155914306641,46.274082183837947 23.116207122802791,46.270610809326172 23.117561340332031,46.269237518310547</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
</Placemark>
</Folder>
</Document></kml>

从现在开始,当用户搜索城市/村庄时,您只需检索边界并在 map 上绘制这些坐标 - https://developers.google.com/maps/documentation/javascript/overlays#Polygons

希望这对您有帮助!祝你好运!

border on Google Map using the above coordinates更新:我使用上面的坐标制作了这座城市的边界

                   var ctaLayer = new google.maps.KmlLayer({
url: 'https://www.dropbox.com/s/0grhlim3q4572jp/ROU_adm2%20-%20Copy.kml?dl=1'
});
ctaLayer.setMap(map);

(我在 Dropbox 上放置了一个包含单个城市边界的小 kml 文件)

请注意,这使用了 Google 内置的 KML 系统,在该系统中,他们的服务器获取文件、计算 View 并将其返回给您 - 它的使用有限,我用它来向您展示边框的外观。在您的应用程序中,您应该能够解析 kml 文件中的坐标,将它们放入数组中(正如多边形文档告诉您的 - https://developers.google.com/maps/documentation/javascript/examples/polygon-arrays )并显示它们。

请注意,Google 在 http://www.google.com/maps 上设置的边框与您通过此数据获得的边框之间存在差异。

祝你好运! enter image description here

更新: http://pastebin.com/x2V1aarJhttp://pastebin.com/Gh55EDW5 这些是来自网站的 javascript 文件(它们被缩小了,所以我使用在线工具使它们可读)。如果您对我的解决方案不完全满意,请随意研究它们。

祝你好运!

关于google-maps - 谷歌地图如何显示城市或区域轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31861822/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com