gpt4 book ai didi

javascript - 使用 Google Earth API 飞到 PlaceResult

转载 作者:行者123 更新时间:2023-11-30 05:40:33 24 4
gpt4 key购买 nike

我已经根据位置搜索获得了一个 PlaceResult 对象,现在我想飞往该位置推荐的 Viewport

这是我目前所拥有的:

function flyToLocation() {
var place = autocomplete.getPlace();
var geometry = place.geometry;
var location = geometry.location;
var viewport = geometry.viewport; // {fa: {b: 70, d: 40}, la: {b: 27, d: 179}}
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
lookAt.setLatitude(location.b);
lookAt.setLongitude(location.d);
lookAt.setTilt(lookAt.getTilt() + 15.0);
lookAt.setRange(500); // todo base this off of viewport
ge.getView().setAbstractView(lookAt);
ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
}

这会将相机对准正确的位置,但范围目前是硬编码的。我想将视口(viewport)作为范围的基础,但我不太确定该怎么做。

问题

  • 我将如何设置范围以使 PlaceResult 的视口(viewport)适合在用户的视口(viewport)内?
  • 或者有更简单的方法吗?

代码一定存在于某处,因为 Google 地球桌面应用程序完美地做到了这一点,但我似乎无法在 API 中找到它。

最佳答案

如果您想将 Viewport (LatLngBounds) 转换为可以在 Google 地球插件中显示的内容,我会推荐 GEarthExtensions Library .

使用它,您可以基于视口(viewport)创建边界对象,然后将其设置为当前 View 。例如

// the viewport is simply the SouthWest and NorthEast points.
var viewport = geometry.viewport;

// create a geo.bounds based on the viewport
var bounds = new geo.Bounds(viewport.getSouthWest(), viewport.getNorthEast());

// set the bounds (viewport) to the GEPlugin view
gex.view.setToBoundsView(bounds, { aspectRatio: 1.0 });

这是一个fully working example .

"The code must exist somewhere because the Google Earth desktop app does this perfectly"

请注意,仅仅因为某些功能存在于一个中,并不意味着它在另一个中可用。事实上,完整应用程序中有很多功能不适用于该插件。

关于javascript - 使用 Google Earth API 飞到 PlaceResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21057769/

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