【发布时间】:2020-12-03 19:35:09
【问题描述】:
我安装了这个包:https://www.npmjs.com/package/@types/googlemaps,创建一个从谷歌地图获取旅行时间的函数,但启动后,我的控制台抛出了我:
Error: Cannot find module 'googlemaps'
我尝试这样导入:
import * as google from 'googlemaps';
但它不起作用,
我也尝试创建index.d.ts:
declare module 'googlemaps';
但没有成功,
我的代码:
var google = require('googlemaps'); // another try
async calculateTravelTime() {
const directionsService = new google.maps.DirectionsService();
directionsService.route(
{
origin: { lat: 37.77, lng: -122.447 },
destination: { lat: 37.768, lng: -122.511 },
travelMode: google.maps.TravelMode.DRIVING
},
(response, status) => {
if(status == "OK") {
console.log(response);
} else {
console.log(response);
}
}
)
}
那么,如何在打字稿中正确导入googlemaps?
感谢您的帮助
【问题讨论】:
-
你关注documentation了吗?
标签: javascript typescript google-maps google-maps-api-3