简体   繁体   English

如何从节点 express mongoose mongoDb 中的地理位置数据中获取城市名称

[英]How can I get city name from geolocation data in node express mongoose mongoDb

I have this document in my collection inside a db in MongoDB我在 MongoDB 的数据库中的集合中有此文档

{
 name: "steve",
 id: 11,
 address: "24 rue Victor Hugo"
 geolocation:
 {latitude:"16.66667",longitude:"101.18333"}
}

I want to get the city name from the geolocation data, I am working in Vs with node, express and mongoose.我想从地理位置数据中获取城市名称,我正在使用 node、express 和 mongoose 在 Vs 中工作。 I tried to find a way to do without manipulating my db, because I already have my collection set before starting.我试图找到一种不操纵我的数据库的方法,因为在开始之前我已经有了我的收藏集。

You can make requests with your geolocation parameters for address information.您可以使用您的地理位置参数请求地址信息。 https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY

What you are trying to do is called reverse geocoding.您正在尝试做的事情称为反向地理编码。 It is available through the Google Maps Geocoding API.它可通过 Google 地图地理编码 API 获得。 You have to sign up for a Google Developers account.您必须注册一个 Google Developers 帐户。 Afterwards, you create a project from the Google Developers console.之后,您从 Google Developers 控制台创建一个项目。 You can then request an API key.然后,您可以请求 API 密钥。 You can then use this API key in your request to the Google Maps API as follows:然后,您可以在对 Google 地图 API 的请求中使用此 API 密钥,如下所示:

https://maps.googleapis.com/maps/api/geocode/json?latlng=16.66667,101.18333&key=YOUR_API_KEY

Take a look at Google's Goecoding API documentation here .此处查看 Google 的 Goecoding API 文档。 You can also test that URL in a browser to see the returned JSON-result, or using curl from the command-line.您还可以在浏览器中测试 URL 以查看返回的 JSON 结果,或从命令行使用curl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将从地理位置获得的城市名称存储到变量中并发送Ajax请求? - How Can I store city name obtained from geolocation to a variable and send ajax request? JavaScript Google Maps Geolocation如何从中获取Zipcode,City,State? - JavaScript Google Maps Geolocation How can I get the Zipcode, City, State from this? 如何使用地理位置获取城市名称并重定向到该城市的URL? - How to get city name using geolocation and redirect to an URL for that city? 如何从地址解析器中仅获取城市名称? - How can I get only the city name from geocoder? 如何从经纬度点获取城市名称? - How can I get city name from a latitude and longitude point? 如何使用此处的反向地理编码从所有检索到的数据中获取城市名称? - How can I get the name of the city from all the retrieved data using here reverse-geocoding? 地理定位 - 如何从长途和拉特获得城市 - Geolocation - how to get city from long and lat 如何获取地理位置数据并将其从浏览器发送到快递服务器 - How to get Geolocation data and send it from browser to express server 节点 JS,我如何使用 ZCCADCDEDB567ABAE643E15DCF0974E503Z 从集合中获取数据 - Node JS, How do i get data from a collection with Mongoose 如何使用猫鼬从 MongoDb 获取数据? - How to get Data from MongoDb using mongoose?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM