__ reactNativeGeocoding.default.setApiKey不是函数

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

我正在尝试获取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
reactjs react-native google-api geocoding
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.