Skip to content

Instantly share code, notes, and snippets.

@watagashi
Last active December 16, 2015 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watagashi/6daf435b756e2451b4f0 to your computer and use it in GitHub Desktop.
Save watagashi/6daf435b756e2451b4f0 to your computer and use it in GitHub Desktop.
'use strict';
var fs = require('fs');
var program = require('commander');
var GoogleMapsAPI = require('googlemaps');
var gapiConf = {
key: 'google API key',
secure: true
};
var gmAPI = new GoogleMapsAPI(gapiConf);
var geocodeParams = {
language: 'ja',
region: 'ja'
};
var data = JSON.parse(fs.readFileSync('data.json'));
var outputFile = 'data.json.out';
for(var i = 0; i < data.length; i++) {
(function(i) {
var address = data[i].address;
geocodeParams.address = address;
gmAPI.geocode(geocodeParams, function(err, result){
if(err) {
console.error('[' + i + ']', 'Parse failed: ', address);
console.log(err);
} else {
var location = result.results[0].geometry.location;
console.log('[' + i + ']',location);
}
});
})(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment