用于React的geolib - 未处理的拒绝(TypeError):无法读取属性' getCenter'未定义的

时间:2017-10-09 13:42:24

标签: javascript reactjs google-maps

使用geolib进行React时,我一直收到此错误。我从geolib导入了geolib和getCenter,但它仍然无法正常工作。这就是我想要做的事情:

calculateMidpoint = (locations) => {
 geolib.getCenter(locations)
 .then(() => {
   debugger
 })
}

但我甚至无法访问我的调试器,因为抛出了这个错误: "未处理的拒绝(TypeError):无法读取属性' getCenter'未定义"。我很困惑,因为我确实导入了geolib,那么我的问题可能是什么呢?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您应该下一步导入geolib

import geolib from 'geolib';

并像这样使用

geolib.getCenter(/* ... */)

import {getCenter} from 'geolib';

// ...
getCenter(/* ... */)

我认为它解决了这个问题。