use*_*286 5 google-geocoder reactjs
我正在尝试使用react-geocode从用户的经纬度坐标中获取地址,但不幸的是我收到错误API keys with referrer restrictions cannot be used with this API.是否可以使用react-geocode允许引荐来源网址限制的不同API?否则我该如何执行此操作,因为我无法删除 API 密钥的引用限制。有没有办法使用我已经用来显示地图的 Google 地图 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);
}
);
Run Code Online (Sandbox Code Playgroud)
如果你想切换到谷歌地图,他们的(反向)地理编码非常简单。显然,您想要获取 Google Maps API 密钥(在此处获取)来编写 GET 请求:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
Run Code Online (Sandbox Code Playgroud)
解析结果应该很容易。:)
资料来源:
| 归档时间: |
|
| 查看次数: |
16253 次 |
| 最近记录: |