Skip to content

Instantly share code, notes, and snippets.

@andikan
Created September 20, 2012 10:15
Show Gist options
  • Save andikan/3755069 to your computer and use it in GitHub Desktop.
Save andikan/3755069 to your computer and use it in GitHub Desktop.
for parsing json
#!/usr/bin/env ruby
# encoding: UTF-8
require 'json'
#require 'mysql2'
require 'geocoder'
Geocoder.configure do |config|
# geocoding service request timeout, in seconds (default 3):
config.timeout = 10
# set default units to kilometers:
config.units = :km
end
input_file = File.open("cm.json").read
input_json = JSON.parse(input_file)
index = 1
input_json.each do |unit|
puts index
unit.keys.each{ |k| puts "#{k} : #{unit[k]}"}
begin
position = Geocoder.search(unit['Address'])
rescue => e
puts "Error"+e.to_s
sleep(0.8)
retry
end
puts "longitude : #{position[0].longitude}"
puts "latitude : #{position[0].latitude}"
index += 1
sleep(0.3)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment