我认为这与我对 javascript 的有限经验有关。我正在使用 Google 提供的 node.js 客户端库,可在此处找到 - https://github.com/googlemaps/google-maps-services-js 该示例展示了如何创建客户端对象
var googleMapsClient = require('@google/maps').createClient({
key: 'your API key here'
});
然后如何运行地理编码请求并打印出结果:
// Geocode an address.
googleMapsClient.geocode({
address: '1600 Amphitheatre Parkway, Mountain View, CA'
}, function(err, response) {
if (!err) {
console.log(response.json.results);
}
});
我需要做的是从文件中读取地址列表并为所有这些对象构建一个对象数组。
我希望我的代码按照以下方式做一些事情:
create address-objects array
create a client object
open the text files
for each line in text files
geocode the line(address)
add the address and the results into an object and add it to the address-objects
我不明白 googleMapsClient.geocode 是否返回某些内容,如果是,我该如何访问它?我应该将它设置为沿线的一些变量:
var gc_results = googleMapsClient.geocode(param , ...)
希望我很清楚,在此先感谢乔纳森。