Typescript中的google.maps.ElevationService无法找到LocationElevationRequest

问题描述 投票:0回答:1

在谷歌地图JS文档中,the example for the elevation service(简称)执行此操作:

var elevator = new google.maps.ElevationService
elevator.getElevationForLocations({
    'locations': [location]
  }, function(results, status) {

  ... etc
})

但是在Typescript中(使用"@types/googlemaps": "3.30.19")我有些奇怪。首先,我不得不使用google.maps.ElevationService.getElevationForLocations()而不是预期的google.maps.ElevationService.prototype.getElevationForLocations()。其次,我遇到的主要问题是我无法访问google.maps.LocationElevationRequest。在打字文件中,我可以看到:

screen shot of google maps typings

但在我的代码中,当我尝试google.maps.LocationElevationRequest我得到一个错误Property 'LocationElevationRequest' does not exist on type 'typeof maps'.没有任意数量插入prototype工作。这是打字的一个漏洞吗? This comment from a few years ago声称它被计算在内。


更新#1

我在其他地方使用google.maps.PolygonOptions,这是与LocationElevationRequest类似的界面:

declare namespace google.maps {

...

  export interface PolygonOptions {
    /**
     * Indicates whether this Polygon handles mouse events. Defaults to true.
     */
    clickable?: boolean;

    ...

  }

  export interface LocationElevationRequest {
    locations: LatLng[];
  }
}
typescript google-maps google-maps-api-3 definitelytyped
1个回答
0
投票

哈哈,我的坏。这是一个打字稿的noob问题。这是正确的方法:

let request: google.maps.LocationElevationRequest = {locations: [e.latLng]}
google.maps.ElevationService.prototype.getElevationForLocations(
    request, (
        results: google.maps.ElevationResult[],
        status: google.maps.ElevationStatus) => {
            ...
        })
© www.soinside.com 2019 - 2024. All rights reserved.