首页 > 解决方案 > _reactNativeGeocoding.default.setApiKey 不是函数

问题描述

我试图在 React Native 中获取给定地址的坐标。我尝试了以下方法:

import Geocoder from 'react-native-geocoding';
    Geocoder.setApiKey("AIz...ZI");
    Geocoder.from("London Eye")
        .then(json => {
            var location = json.results[0].geometry.location;
            console.log(location);
        })
        .catch(error => console.warn(error));

我把“...”放在 API 中只是为了隐藏整个密钥。

当我调用此代码所在的方法时,出现错误:

_reactNativeGeocoding.default.setApiKey is not a function

标签: reactjsreact-nativegoogle-apigeocoding

解决方案


要设置 api 密钥,您需要调用“init”方法而不是 setApiKey

   Geocoder.init('AIz...ZI');

推荐阅读