【发布时间】:2019-12-26 23:59:19
【问题描述】:
我正在尝试使用react-geocode 从他们的纬度/经度坐标中获取用户的地址,但不幸的是我收到了错误API keys with referrer restrictions cannot be used with this API. 是否有可能让react-geocode 使用不同的 API,它确实允许推荐人限制?否则我将如何去做,因为我无法删除我的 API 密钥的引用者限制。有没有办法使用我已经用来显示我的地图的 Google Maps API 来反转地理编码纬度/经度坐标?
import Geocode from "react-geocode";
Geocode.setApiKey("AIzaSyDsb7F-VyBJn7r4LilYH_lRHBpPfgyUga8");
Geocode.enableDebug();
Geocode.fromLatLng("48.8583701", "2.2922926").then(
response => {
const address = response.results[0].formatted_address;
console.log(address);
},
error => {
console.error(error);
}
);
CodeSandbox
【问题讨论】:
-
使用开源地图。例如,您可以使用
react-leaflet和leaflet-control-geocoder代替谷歌地图