Skip to content

Instantly share code, notes, and snippets.

@yhsiang
Created July 17, 2013 10:53
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 yhsiang/6019552 to your computer and use it in GitHub Desktop.
Save yhsiang/6019552 to your computer and use it in GitHub Desktop.
var http = require('httpsync')
, fs = require('fs');
var getLocation = function (address, callback) {
var url, req, res, results, location;
url = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text='+address+'&f=pjson';
req = http.get(url);
res = req.end();
if(JSON.parse(res.data).locations.length > 0 ) {
results = JSON.parse(res.data).locations[0];
location = results.feature.geometry;
callback(location);
}
};
var json =fs.readFileSync('public/data/farms.json');
var farms = JSON.parse(json.toString()).farms;
farms.forEach(function (d, i) {
if(d.address.match(/號/) ) {
getLocation(d.address.replace(/ /g,''), function(location) {
d.location = location;
console.log(JSON.stringify(d)+',');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment