Google 地图、KML 还是 JSON 哪种数据源更可取?

发布于 2024-10-04 06:18:50 字数 144 浏览 0 评论 0原文

我完全看到了 JSON 的好处,将轻量级数据数组放入我的 Google 地图中(并通过模板显示点列表)。我听过很多关于 KML 的讨论。

将点拉入 Google 地图、JSON 的最佳方式是哪种 || KML?我主要关心的是性能,还有可能改进地图的功能广度。

I totally see the benefits of JSON, pull over a lightweight array of data to stuff into my Google Maps (and template through to show a list of the points as well). I've heard a lot of talk about KML.

Which is the preferable way to pull points into Google Maps, JSON || KML? My primary concern is performance, but also breadth of features that could potentially improve the map.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

酒浓于脸红 2024-10-11 06:18:50

我个人使用 json,因为 kml 生成的功能不如通过解析 json 创建的功能灵活。例如,您无法从 kml 将悬停事件添加到多边形。

Personally I use json because the kml resulting features are less flexible than the features that you create from parsing json. For example, you can't add a hover event to a polygon from kml.

何必那么矫情 2024-10-11 06:18:50

如果您只是加载更简单的数据,那么与 JSON 相比,KML 作为 XML 是非常的重量级,并且不仅会在网络传输方面而且会在解析时间方面遭受性能损失。当然,这就是 JSON 的缺点,它不仅限制了潜在的表达能力(取决于 Google 地图组件可以通过 JSON 与 KML 消耗什么),还限制了哪些客户端可以消耗您的数据。如果您以 KML 格式提供数据,则任何读取 KML 的设备都可以使用您的数据,例如 Google 地球。它就像地理数据的 RSS,如果您想要或需要它的话。

KML, being XML, is very heavyweight compared to JSON if you're just loading simpler data and will suffer performance penalties not only in network transfer but in parsing time as a result. That's the downside to JSON, of course, is that you're limited not only in expressive power potentially (depending on what the Google Maps components can consume via JSON versus KML), but also on which clients can consume your data. If you give your data in KML, anything that reads KML can use your data, like Google Earth. It's like the RSS of geographic data, that is if you want or need it to be.

故事未完 2024-10-11 06:18:50

在过去的几个月里,我使用 OpenLayers 做了很多工作,并且非常喜欢它。该库是开源的,包含大量开箱即用的格式,包括 GeoJSONKML这是其余示例。结合 OpenLayers 和 ExtJS ,结果是 ExtJS 。 geoext.org/" rel="nofollow noreferrer">GeoExt(示例此处)。

These past few months I've done a lot of work with OpenLayers and have really enjoyed it. The library is open source and includes tons of formats out of the box including GeoJSON and KML. Here's the rest of the examples. Combined OpenLayers and ExtJS and it results in GeoExt (examples here).

空心空情空意 2024-10-11 06:18:50

我想为 KML 辩护,特别是在 Google 地图的背景下:

  1. KML 是一个官方标准 由 OGC 策划;
  2. Google 本身首先创建 KML,并维护广泛的文档< /a> 关于它。它甚至还有一个用于 KML 的
  3. Google 地图 API 对 KML 图层 提供了良好的支持(尽管它也有良好的支持) 支持 GeoJSON);
  4. 许多其他 Google 地图应用程序(Google 地球、Google 我的地图、Google 地图路由)原生导出 KML,或提供将数据下载/保存为 KML。据我所知,导入/导出功能还没有为 GeoJSON 开发,至少目前为止(截至 2016 年)。

I would like to make a case for KML, specially in the context of Google Maps:

  1. KML is an official standard curated by OGC;
  2. Google itself has created KML in the first place, and maintains an extensive documentation about it. It even has a library for KML;
  3. Google maps API has good support for KML Layers (although it also has good support for GeoJSON);
  4. A lot of other Google mapping applications (Google Earth, Google My Maps, Google Maps Routing) export KML natively, or offer to download/save the data as KML. That Import/Export functionality, as far as I know, is not so developed for GeoJSON, at least yet (as of 2016).
生生漫 2024-10-11 06:18:50

您可以在 KMZ、KML 和 GeoJSON 之间进行转换:

KMZ 只是 KML 文件的 ZIP 存档。所以至少KMZ -> KML 很容易。

# GeoJSON -> KML
$ ogr2ogr -f 'KML' -a_srs EPSG:4326 output.kml input.geojson

# KML -> GeoJSON
$ ogr2ogr -preserve_fid -f GeoJSON -a_srs EPSG:4326 output.geojson input.kml

另外,

# KML -> GeoJSON
$ pip3 install kml2geojson --user
$ k2g input.kml output_directory

如果上传速度是一个问题,我会选择压缩文件。我的猜测:对于小数据,GeoJSON 会更小,如果您的功能变得更复杂,KMZ 会更小。但我很高兴看到一些基准/数字/示例。

You can convert between KMZ, KML and GeoJSON:

KMZ is simply a ZIP archive of a KML file. So at least KMZ -> KML is easy.

# GeoJSON -> KML
$ ogr2ogr -f 'KML' -a_srs EPSG:4326 output.kml input.geojson

# KML -> GeoJSON
$ ogr2ogr -preserve_fid -f GeoJSON -a_srs EPSG:4326 output.geojson input.kml

And also

# KML -> GeoJSON
$ pip3 install kml2geojson --user
$ k2g input.kml output_directory

If upload speed is a concern, I would go with the compressed file. My guess: GeoJSON is way smaller for small data, KMZ is way smaller if your Features become more complex. But I'd be happy to see some benchmarks / numbers / examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文