thecodecrate / city-state Goto Github PK
View Code? Open in Web Editor NEWSimple ruby gem to create form lists with cities and states
License: MIT License
Simple ruby gem to create form lists with cities and states
License: MIT License
Hello guys, I see that we are missing few cities from the database. For example:
Florida
missing : coconut creek, coral springs, margate, just to list a few.
What is the best way to add them?
thanks
Im getting this error when trying to get the countries:
undefined method `countries' for CS:Module
I noticed that the method is not there anymore.
I just found out that there's no "all cities list" or anything related, and I needed that to check if an city exists.
I would like to list all cities of all countries and all states to check if a certain city exists or not, and for that i would need to iterate all it over. Would be better to have an method available to get all cities or check if a certain city exists or maybe both.
This gem returns completely invalid data for GB:
irb(main):001:0> CS.get(:gb)
{:ENG=>"England",
:KEN=>"Kent",
:LND=>"City of London",
:NIR=>"Northern Ireland",
:SCT=>"Scotland",
:SOM=>"Somerset",
:SRY=>"Surrey",
:WLS=>"Wales"}
It returns a mixture of counties, local government, countries and provinces. It should probably refer to ISO 3166-2:GB
, and return the codes for what that considers countries and provinces.
CS.countries
also includes the following pair in the array:
:COUNTRY_ISO_CODE => "country_name"
Hi, the names retrieved by maxmind are always english name I could check that the gem only look up for the english names, would be better if it searches the names based on the locale of the rails application, or even better pass that as an argument in the CS
call
Hi all,
I've used the following as a means to generate all Irish cities,
module MyApp
class Country
def initialize(country_code)
@country_code = country_code
end
def cities
cities = []
state_keys = get_states.keys
state_keys.each do |state|
cities << ::CS.cities(state, @country_code)
end
cities.flatten.uniq.sort
end
private
def get_states
::CS.get(@country_code)
end
end
end
However, this does not seem to be complete?
[1] pry(main)> MyApp::Country.new(:ie).cities
=> ["Abbeydorney",
"Abbeyfeale",
"Abbeyleix",
"Achill",
"Adare",
"Allenwood",
"Annacotty",
"Ardee",
"Arklow",
"Artane",
"Ashbourne",
"Ashtown",
"Athboy",
"Athenry",
"Athlone",
"Athy",
"Bagenalstown",
"Bailieborough",
"Balbriggan",
"Baldoyle",
"Ballaghaderreen",
"Ballina",
"Ballinagleragh",
"Ballinalee",
"Ballinasloe",
"Ballincollig",
"Ballinhassig",
"Ballinrobe",
"Ballitore",
"Ballsbridge",
"Ballyboden",
"Ballybrittas",
"Ballydesmond",
"Ballyduff",
"Ballyfermot",
"Ballyjamesduff",
"Ballymacelligott",
"Ballymahon",
"Ballymore Eustace",
"Ballymun",
"Ballyshannon",
"Ballyvaghan",
"Baltinglass",
"Bandon",
"Bantry",
"Barrack",
"Beaumont",
"Belgooly",
"Bettystown",
"Birr",
"Blackpool",
"Blackrock",
"Blanchardstown",
"Blarney",
"Blessington",
"Boyle",
"Bray",
"Bruff",
"Bruree",
"Buncrana",
"Bunratty",
"Burren",
"Cabinteely",
"Cabra",
"Caher",
"Cappoquin",
"Carbury",
"Carlow",
"Carndonagh",
"Carraroe",
"Carrick",
"Carrick on Shannon",
"Carrick-on-Suir",
"Carrickmacross",
"Carrickmines",
"Carrigaline",
"Carrigallen",
"Carrigtohill",
"Cashel",
"Castlebar",
"Castleblayney",
"Castleknock",
"Cavan",
"Celbridge",
"Clane",
"Clara",
"Clarecastle",
"Claregalway",
"Claremorris",
"Clogherhead",
"Clonakilty",
"Clondalkin",
"Clonee",
"Clonmel",
"Clonsilla",
"Clontarf",
"Cobh",
"Collinstown",
"Cork",
"Crumlin",
"Dalkey",
"Delgany",
"Donabate",
"Donacarney",
"Donaghmore",
"Donegal",
"Donnybrook",
"Donore",
"Douglas",
"Drogheda",
"Droichead Nua",
"Dromahair",
"Dromore West",
"Drumcondra",
"Dublin",
"Duleek",
"Dunboyne",
"Dundalk",
"Dundrum",
"Dungarvan",
"Dunglow",
"Dunlavin",
"Dunleer",
"Dunmanway",
"Dunshaughlin",
"Dún Laoghaire",
"Edenderry",
"Enfield",
"Ennis",
"Enniscorthy",
"Fermoy",
"Finglas",
"Firhouse",
"Foxford",
"Foxrock",
"Galway",
"Garristown",
"Glasnevin",
"Glassan",
"Glenageary",
"Gorey",
"Gort",
"Granard",
"Greystones",
"Harold's Cross",
"Headford",
"Howth",
"Islandbridge",
"Kanturk",
"Kells",
"Kenmare",
"Kilbarrack",
"Kilbeggan",
"Kilbride Cross Roads",
"Kilcock",
"Kilcoole",
"Kildalkey",
"Kildare",
"Kilfinane",
"Kilkee",
"Kilkenny",
"Kilkishen",
"Killaloe",
"Killarney",
"Killeshin",
"Killiney",
"Killucan",
"Kilmessan",
"Kiltamagh",
"Kingswood",
"Kinnegad",
"Kinsale",
"Kinvarra",
"Lanesborough",
"Laytown",
"Leixlip",
"Leopardstown",
"Letterkenny",
"Lifford",
"Limerick",
"Listowel",
"Longford",
"Longwood",
"Loughlinstown",
"Loughrea",
"Louth",
"Lucan",
"Lusk",
"Macroom",
"Malahide",
"Mallow",
"Marino",
"Maynooth",
"Mayo",
"Midleton",
"Mitchelstown",
"Moate",
"Monaghan",
"Monamolin",
"Monkstown",
"Mornington",
"Mountshannon",
"Moville",
"Mullingar",
"Multyfarnham",
"Naas",
"Naul",
"Navan",
"Nenagh",
"New Quay",
"New Ross",
"Newcastle",
"Newcastle West",
"Newmarket",
"Newport",
"Nohaval",
"Oranmore",
"Oughterard",
"Ovens",
"Piltown",
"Portarlington",
"Porterstown",
"Portlaoise",
"Portmarnock",
"Portumna",
"Quin",
"Raheny",
"Rath Luirc",
"Rathanna",
"Rathcoole",
"Rathfarnham",
"Rathmines",
"Rathmore",
"Ratoath",
"Rhode",
"Ringsend",
"Riverstown",
"Rochestown",
"Rochfortbridge",
"Roscommon",
"Roscrea",
"Rush",
"Saggart",
"Sallins",
"Sandycove",
"Sandyford",
"Sandymount",
"Santry",
"Shankill",
"Shannon",
"Sixmilebridge",
"Skerries",
"Slane",
"Sligo",
"Spiddal",
"Stepaside",
"Stillorgan",
"Streamstown",
"Summerhill",
"Sutton",
"Swinford",
"Swords",
"Taghmon",
"Tallaght",
"Templeogue",
"Terenure",
"Thurles",
"Tipperary",
"Tralee",
"Tramore",
"Trim",
"Tuam",
"Tullamore",
"Tullow",
"Virginia",
"Waterfall",
"Waterford",
"Watergrasshill",
"Westport",
"Wexford",
"Wicklow",
"Youghal"]
For example, the city/town of Oldcastle
is missing, and I'm sure there are many more. Appreciate any advice please.
I'm having an issue while adding a missing city.
The first one is that is raising an error but I opened a PR for that: #66
The second one is that when I add a missing city, if I try to find cities for a state other the one that I added, it does not load the city. It only loads the new city if I call .cities
first for the state that I'm adding the missing record.
Example:
db/cities-lookup.yml
BR:
GO:
"Mutunópolis": "Mutunópolis"
If I load first cities for other state, it does not include this missing city:
bin/rails c
CS.cities(:sp, :br) # loading another state first
CS.cities(:go, :br).include?("Mutunópolis")
#> false
returned false but it should be true.
If I load this state first, it works correctly
bin/rails c
CS.cities(:go, :br).include?("Mutunópolis")
#> true
do u folks have any idea why this is happening? Thanks
Dear Author,
I have installed the city-state (0.0.11) and tried to load countries and its loading but states are not loading as in my system I am getting the following issue.
Errno::EACCES: Permission denied - /home/bitla-b10/.rvm/gems/ruby-1.9.3-p547/gems/city-state-0.0.11/lib/db/states.in
from /home/bitla-b10/.rvm/gems/ruby-1.9.3-p547/gems/city-state-0.0.11/lib/city-state.rb:104:in `initialize'
It seems its requiring some missed files.
Thanks in Advance.
Hi,
This gem is vey much helpful to me.
But I wanted to know the list of countires. Is there a method to get the complete list of countries so that I can use that.
Because to get the states I need to pass the country code hence to get the country code I need the countries list.
Thank you in Advance.
I've noticed an issue with the cities data. It's not in a predictable format. I've been writing a helper to deal with abbreviations but then I noticed that some cities in the datafile have the word 'saint' spelled out, others have 'st' and others have 'st.'
Here are a few examples from: CS.cities(:MO, 'US')
"Saint Albans",
"Saint Ann",
"Saint Clair",
"Saint Elizabeth",
"Saint James",
"Saint Mary",
"Saint Robert",
"Saint Thomas",
"St Louis",
"St. Charles",
"St. Genevieve",
"St. Joseph"
Would it possible to add the feature for finding the capital city of selected country and state ?
Ex: Davie is a city in Florida but it does not show on drop down
Bronx is a city in New York but it does not show on drop down
Ruby with version 3.2.2 removed method exists?
for class File
Need to change exists?
to exist?
Passing nil
as an argument to the CS.states
method returns {:V=>"Iles du Vent"}. It should probably return an empty hash.
I love your gem. However, ether CS.update
downloads all the cities in the world (which is a bit much), or if it doesn't and it's sending a request to out every time I ask for a City.
Would be nice to filter this down, and specify what countries' cities you want to download.
the presented on readme link returns a xml
https://www.learnwithdaniel.com/2015/02/citystate-list-of-cities-and-states-ruby/
the actual link is
https://www.learnwithdaniel.com/2015/02/citystate-list-of-countries-cities-and-states-ruby/
Hi,
Kindly add the code for Telangana (a state in India). As of now in your DB the code is blank.
I request you kindly add the code TG for Telangana.
I tried in my rails console CS.cities(:rj, :in)
it renders me ["Ajmer", "Alwar", "Amer", "Amet", "Balana", "Bali", "Banswara", "Barmer", "Beawar", "Bharatpur", "Bhilwara", "Bikaner", "Binavas", "Bundi", "Charu", "Chetan", "Chhabra", "Dipas", "Ganganagar", "Gangapur", "Gangrar", "Jaipur", "Jaisalmer", "Jhalawar", "Jhunjhunun", "Jodhpur", "Kalan", "Kanakpura", "Khan", "Khinwara", "Kishangarh", "Kolayat", "Kota", "Lamba Harisingh", "Mahajan", "Mahatma", "Mandal", "Manna", "Mount Abu", "Nagar", "Nagaur", "Nanda", "Naraina", "Nathdwara", "Pali", "Pilani", "Pitampura", "Pushkar", "Rana", "Roshan", "Shiv", "Sikar", "Sirohi", "Sojat", "Sultan", "Surana", "Suratgarh", "Thali", "Tonk", "Udaipur"]
where as no such cities like chetan
, Roshan
, Mahatma
, Khan
etc. are not exist in rajasthan and some name like Shiv
, Balana
, Bali
, Binavas
, Dipas
etc are small town/village in cities of rajasthan.
Hello,
Thanks for the gem, it's really necessary in web development...
But I have a problem with the methods... they only answer me the country name...
This is my development enviroment:
Mac platform
RVM
Ruby 2.1.1
Rails 4.1.6
let me show you the results of my rails console:
2.1.1 :043 > CS.get
=> {:AD=>"Andorra", :AE=>"United Arab Emirates", :AF=>"Afghanistan", :AG=>"Antigua and Barbuda",
Wich is OK!
Then when i try to send the Bolivia code :BO even the US code...
2.1.1 :044 > CS.get :bo
=> "Bolivia"
2.1.1 :045 > CS.get :us
=> "United States"
OK... lets try the other methods:
2.1.1 :046 > CS.states(:us)
=> "United States"
2.1.1 :047 > CS.states(:bo)
=> "Bolivia"
OK... I'll spent some time checking the code and I went to my gem directory and I found this file GeoLite2-City-Locations-en.csv, at the begining i tought maybe this is a permission problem, i changed the cmod to 777 just to test... and the answer is the same...
Then i tryed to get the Cities:
2.1.1 :051 > CS.cities(:bo, :s)
=> []
and then i tryed to do the same with US:
CS.cities(:us, :or)
=> []
2.1.1 :061 > CS.cities(:us, :nv)
=> []
then i try a random State code...
CS.cities(:us, :pa)
TypeError: no implicit conversion of Symbol into Integer
from /Users/svonborries/.rvm/gems/ruby-2.1.1@seru/gems/city-state-0.0.12/lib/city-state.rb:145:in `[]'
from /Users/svonborries/.rvm/gems/ruby-2.1.1@seru/gems/city-state-0.0.12/lib/city-state.rb:145:in `cities'
from (irb):62
Am I missing something??? or maybe it's something related to my SO (Snow Leopard)
Please give me a hand with this... I really want to use yout gem.
Have a great Day,
Sergio,
Hello. It seems maxmind stoped support of this DB url. So CS.update went to endless loop trying to access url.
If someone had issue with endless cycle of errors - remove CS.update from your codebase. Next step will be fixing url inside this lib and creating error handler to prevent errors in future with accessing to DB's.
Thanks.
Hello, I have a problem with the gem. I want to rename and delete some city, becouse these are wrong, but when I try this the gem doesnt work, I created the file city-loockup.yml but this didnt work is so frustrating becouse the gem is so good. I had not problem change the state or the countries, is possible to rename, add or delete. But I cant with the cities.
CO: NAR: "Anganoy": "" "Buga": "" "Cartago": "" "Chaparral": "" "Girardot": "" "Imues": "La Union" "Alban": "Alban" "Aldana": "Aldana" "Ancuya": "Ancuya"
For example sometimes the cities Anganoy, Buga, Cartago, Chaparral and Girardot are delete but sometimes dont. And never I can created the cities Alban, Aldana, Ancuya.
Can we have an api for search as well, where we get these things,
- when city name matches with the key word display city, state, country
- when state name alone matches with the key word display state, country
- when country name alone matches with the key word display country
Say, when I search for 'Ind' I expect the following results,
- "Ananindeua,Para,Brazil"
- "Olinda,Pernambuco,Brazil"
- "Gindou,Midi-Pyrenees,France"
- "India"
- "Indore,Madhya Pradesh,India"
- "Windsor,Connecticut,USA"
- "Indiana,Pennsylvania,USA"
- "Indiana,USA"
CS.search('Ind')
When no additional parameters is given it would search in all (cities, states and countries).
We can have additional parameters as well like,
CS.search('Ind', :country) will search only in countries
CS.search('Ind', :state) will search only in states
CS.search('Ind', :city) will search only in cities
CS.search('Ind', :country, :state) will search only in states and countries
CS.search('Ind', :country, :city) will search only in cities and countries
CS.search('Ind', :city, :state) will search only in states and cities
This is awesome gem, but only one thing I found which is not there is zipcodes with the cities.
NY seems to have some issue getting correct city list.
Result:
>> CS.cities :ny, :us
=> ["Accord", "Acra", "Adams", "Addison", "Afton", "Akron", "Albany", "Albertson", "Albion", "Alden", "Alexander", "Alexandria Bay", "Alfred", "Alfred Station", "Allegany", "Almond", "Alplaus", "Altamont", "Altmar", "Altona", "Amagansett", "Amawalk", "Amenia", "Amherst", "Amityville", "Amsterdam", "Andes", "Andover", "Angelica", "Angola", "Annandale-on-Hudson", "Apalachin", "Aquebogue", "Arcade", "Ardsley", "Argyle", "Arkport", "Armonk", "Arverne", "Ashville", "Astoria", "Athens", "Atlantic Beach", "Attica", "Au Sable Forks", "Auburn", "Aurora", "Austerlitz", "Ava", "Averill Park", "Avoca", "Avon", "Babylon", "Bainbridge", "Baldwin", "Baldwin Place", "Baldwinsville", "Ballston Lake", "Ballston Spa", "Barryville", "Barton", "Batavia", "Bath", "Bay Shore", "Bayport", "Bayside", "Bayville", "Beacon", "Bearsville", "Beaver Dams", "Bedford", "Bedford Hills", "Bellerose", "Bellmore", "Bellport", "Belmont", "Bemus Point", "Bergen", "Berkshire", "Berlin", "Berne", "Bernhards Bay", "Bethpage", "Big Flats", "Binghamton", "Blauvelt", "Blooming Grove", "Bloomingburg", "Blossvale", "Blue Point", "Bohemia", "Boiceville", "Bolivar", "Bolton Landing", "Bombay", "Boonville", "Boston", "Bovina Center", "Bowmansville", "Bradford", "Branchport", "Brant Lake", "Brasher Falls", "Brentwood", "Brewerton", "Brewster", "Briarcliff Manor", "Bridgehampton", "Bridgeport", "Brightwaters", "Broadalbin", "Brockport", "Brocton", "Bronxville", "Brookfield", "Brookhaven", "Brooklyn", "Brooktondale", "Brushton", "Buchanan", "Buffalo", "Burdett", "Burlington Flats", "Burnt Hills", "Burt", "Byron", "Cadyville", "Cairo", "Caledonia", "Callicoon", "Calverton", "Cambria Heights", "Cambridge", "Camden", "Cameron Mills", "Camillus", "Campbell", "Campbell Hall", "Canajoharie", "Canandaigua", "Canastota", "Candor", "Canisteo", "Canton", "Cape Vincent", "Carle Place", "Carmel", "Caroga Lake", "Carthage", "Cassadaga", "Cassville", "Castile", "Castleton-on-Hudson", "Castorland", "Cato", "Catskill", "Cattaraugus", "Cayuga", "Cazenovia", "Cedarhurst", "Celoron", "Center Moriches", "Centereach", "Centerport", "Central Islip", "Central Square", "Central Valley", "Chadwicks", "Champlain", "Chappaqua", "Chatham", "Chaumont", "Chazy", "Chemung", "Chenango Forks", "Cherry Creek", "Cherry Valley", "Chester", "Chestertown", "Chittenango", "Churchville", "Cicero", "Cincinnatus", "Circleville", "Clarence", "Clarence", "Claverack", "Clay", "Clayton", "Cleveland", "Clifton Park", "Clifton Springs", "Climax", "Clinton", "Clinton Corners", "Clintondale", "Clyde", "Clymer", "Cobleskill", "Coeymans", "Cohocton", "Cohoes", "Cold Brook", "Cold Spring", "Cold Spring Harbor", "College Point", "Colton", "Commack", "Comstock", "Conesus", "Congers", "Conklin", "Constantia", "Cooperstown", "Copake", "Copake Falls", "Copenhagen", "Copiague", "Coram", "Corfu", "Corinth", "Corning", "Cornwall-on-Hudson", "Cornwallville", "Corona", "Cortland", "Coxsackie", "Cragsmoor", "Cranberry Lake", "Craryville", "Crompond", "Cropseyville", "Cross River", "Croton Falls", "Croton-on-Hudson", "Crown Point", "Cuba", "Cuddebackville", "Cutchogue", "Dalton", "Dansville", "Darien Center", "De Kalb Junction", "Deansboro", "Deer Park", "Delanson", "Delevan", "Delhi", "Delmar", "Denver", "Depew", "Deposit", "Derby", "Dewittville", "Dexter", "Dickinson Center", "Dobbs Ferry", "Dodgewood", "Dolgeville", "Dover Plains", "Downsville", "Dryden", "Duanesburg", "Dundee", "Dunkirk", "Durham", "Durhamville", "Eagle Bridge", "Earlville", "East Amherst", "East Aurora", "East Berne", "East Branch", "East Chatham", "East Concord", "East Durham", "East Elmhurst", "East Greenbush", "East Hampton", "East Islip", "East Marion", "East Meadow", "East Meredith", "East Moriches", "East Nassau", "East Northport", "East Norwich", "East Otto", "East Pharsalia", "East Quogue", "East Rochester", "East Rockaway", "East Setauket", "East Syracuse", "Eastchester", "Eastport", "Eden", "Edmeston", "Edwards", "Elbridge", "Eldred", "Elizaville", "Elka Park", "Ellenville", "Ellicottville", "Elma", "Elmhurst", "Elmira", "Elmont", "Elmsford", "Endicott", "Erieville", "Erin", "Esopus", "Essex", "Fabius", "Fair Haven", "Fairport", "Falconer", "Fallsburg", "Far Rockaway", "Farmingdale", "Farmington", "Farmingville", "Fayetteville", "Feura Bush", "Fillmore", "Fishers", "Fishers Island", "Fishers Landing", "Fishkill", "Fleischmanns", "Floral Park", "Florida", "Flushing", "Fonda", "Forest Hills", "Fort Ann", "Fort Covington", "Fort Drum", "Fort Edward", "Fort Johnson", "Fort Montgomery", "Fort Plain", "Frankfort", "Franklin", "Franklin Square", "Franklinville", "Fredonia", "Freedom", "Freehold", "Freeport", "Fresh Meadows", "Frewsburg", "Friendship", "Fulton", "Fultonville", "Gainesville", "Galway", "Gansevoort", "Garden City", "Gardiner", "Garnerville", "Garrison", "Gasport", "Geneseo", "Geneva", "Genoa", "Georgetown", "Germantown", "Getzville", "Ghent", "Gilboa", "Glen Cove", "Glen Head", "Glen Oaks", "Glen Spey", "Glenfield", "Glenham", "Glenmont", "Glens Falls", "Glenwood", "Glenwood Landing", "Gloversville", "Goldens Bridge", "Goshen", "Gouverneur", "Gowanda", "Grahamsville", "Grand Island", "Granite Springs", "Granville", "Great Neck", "Great River", "Great Valley", "Greene", "Greenfield Center", "Greenlawn", "Greenport", "Greenvale", "Greenville", "Greenwich", "Greenwood Lake", "Groton", "Groveland", "Guilderland", "Guilford", "Hamburg", "Hamden", "Hamilton", "Hamlin", "Hammondsport", "Hampton Bays", "Hancock", "Hannibal", "Harford", "Harpursville", "Harriman", "Harrison", "Hartsdale", "Hastings", "Hastings-on-Hudson", "Hauppauge", "Haverstraw", "Hawthorne", "Hector", "Hemlock", "Hempstead", "Henrietta", "Hensonville", "Herkimer", "Hermon", "Heuvelton", "Hewlett", "Hicksville", "High Falls", "Highland", "Highland Falls", "Highland Mills", "Hillburn", "Hillsdale", "Hilton", "Hobart", "Hogansburg", "Holbrook", "Holland", "Holland Patent", "Holley", "Hollis", "Holmes", "Holtsville", "Homer", "Honeoye", "Honeoye Falls", "Hoosick", "Hoosick Falls", "Hopewell Junction", "Hornell", "Horseheads", "Houghton", "Howard Beach", "Howells", "Howes Cave", "Hubbardsville", "Hudson", "Hudson Falls", "Huguenot", "Hume", "Hunter", "Huntington", "Huntington Station", "Hurley", "Hurleyville", "Hyde Park", "Ilion", "Indian Lake", "Inlet", "Interlaken", "Inwood", "Irvington", "Island Park", "Islandia", "Islip", "Islip Terrace", "Ithaca", "Jackson Heights", "Jamaica", "Jamesport", "Jamestown", "Jamesville", "Jasper", "Jay", "Jefferson Valley", "Jeffersonville", "Jericho", "Johnson", "Johnson City", "Johnstown", "Jordan", "Jordanville", "Katonah", "Keene Valley", "Keeseville", "Kendall", "Kennedy", "Kerhonkson", "Keuka Park", "Kew Gardens", "Kiamesha Lake", "Kinderhook", "Kings Park", "Kingston", "Kirkville", "Kirkwood", "La Fargeville", "LaFayette", "Lacona", "Lagrangeville", "Lake George", "Lake Grove", "Lake Katrine", "Lake Luzerne", "Lake Peekskill", "Lake Placid", "Lake Pleasant", "Lake View", "Lakeville", "Lakewood", "Lancaster", "Lansing", "Larchmont", "Latham", "Laurel", "Laurens", "Lawrence", "Le Roy", "Lee Center", "Leeds", "Leicester", "Levittown", "Lewis", "Lewiston", "Liberty", "Lily Dale", "Lima", "Lincolndale", "Lindenhurst", "Lindley", "Lisbon", "Lisle", "Little Falls", "Little Neck", "Little Valley", "Liverpool", "Livingston Manor", "Livonia", "Loch Sheldrake", "Locke", "Lockport", "Locust Valley", "Long Beach", "Long Island", "Long Lake", "Lowman", "Lowville", "Lynbrook", "Lyons", "Macedon", "Machias", "Madison", "Madrid", "Mahopac", "Mallory", "Malone", "Malverne", "Mamaroneck", "Manhasset", "Manlius", "Mannsville", "Manorville", "Marathon", "Marcellus", "Marcy", "Margaretville", "Marietta", "Marilla", "Marion", "Marlboro", "Martville", "Maspeth", "Massapequa", "Massapequa Park", "Massena", "Mastic", "Mastic Beach", "Mattituck", "Maybrook", "Mayfield", "Mayville", "Mechanicville", "Medford", "Medina", "Medusa", "Melrose", "Melville", "Merrick", "Mexico", "Middle Grove", "Middle Island", "Middle Village", "Middleburgh", "Middleport", "Middlesex", "Middletown", "Millbrook", "Miller Place", "Millerton", "Millport", "Millwood", "Milton", "Mineola", "Minetto", "Mineville", "Minoa", "Modena", "Mohawk", "Mohegan Lake", "Moira", "Monroe", "Monsey", "Montauk", "Montgomery", "Monticello", "Montour Falls", "Montrose", "Mooers", "Mooers Forks", "Moravia", "Moriah", "Moriches", "Morris", "Morrisonville", "Morrisville", "Mount Kisco", "Mount Morris", "Mount Sinai", "Mount Tremper", "Mount Upton", "Mount Vernon", "Mount Vision", "Mountain Dale", "Mountainville", "Munnsville", "Nanuet", "Naples", "Narrowsburg", "Nassau", "Natural Bridge", "Nedrow", "Nesconset", "Neversink", "New Berlin", "New City", "New Hampton", "New Hartford", "New Hyde Park", "New Lebanon", "New Milford", "New Paltz", "New Rochelle", "New Suffolk", "New Windsor", "New Woodstock", "New York", "New York Mills", "Newark", "Newburgh", "Newcomb", "Newfield", "Newport", "Niagara Falls", "Nichols", "Nicholville", "Norfolk", "North Babylon", "North Bangor", "North Bay", "North Chili", "North Collins", "North Creek", "North Greece", "North Java", "North Rose", "North Salem", "North Tonawanda", "Northport", "Northrup's of West Bloomfield Mobile Home Park", "Northville", "Norwich", "Norwood", "Nunda", "Nyack", "Oak Hill", "Oakdale", "Oakfield", "Oakland Gardens", "Ocean Beach", "Oceanside", "Odessa", "Ogdensburg", "Old Bethpage", "Old Chatham", "Old Forge", "Old Westbury", "Olean", "Olivebridge", "Olmstedville", "Oneida", "Oneonta", "Ontario", "Orangeburg", "Orchard Park", "Oriskany", "Oriskany Falls", "Ossining", "Oswego", "Otego", "Otisville", "Ovid", "Owego", "Oxford", "Oyster Bay", "Ozone Park", "Painted Post", "Palatine Bridge", "Palenville", "Palisades", "Palmyra", "Panama", "Parish", "Patchogue", "Patterson", "Pattersonville", "Paul Smiths", "Pavilion", "Pawling", "Pearl River", "Peconic", "Peekskill", "Pelham", "Penfield", "Penn Yan", "Pennellville", "Perry", "Peru", "Petersburg", "Phelps", "Philadelphia", "Philmont", "Phoenix", "Piermont", "Pine Bush", "Pine City", "Pine Hill", "Pine Plains", "Pine Valley", "Pitcher", "Pittsford", "Plainview", "Plattsburgh", "Pleasant Valley", "Pleasantville", "Poestenkill", "Point Lookout", "Pomona", "Pompey", "Port Byron", "Port Chester", "Port Crane", "Port Ewen", "Port Gibson", "Port Henry", "Port Jefferson", "Port Jefferson Station", "Port Jervis", "Port Washington", "Portageville", "Porter Corners", "Portland", "Portville", "Potsdam", "Pottersville", "Poughkeepsie", "Poughquag", "Pound Ridge", "Prattsburgh", "Prattsville", "Pulaski", "Purchase", "Purdys", "Purling", "Putnam Valley", "Queens Village", "Queensbury", "Quogue", "Randolph", "Ransomville", "Ravena", "Red Creek", "Red Hook", "Redwood", "Rego Park", "Remsen", "Remsenburg", "Rensselaer", "Rexford", "Rhinebeck", "Richfield Springs", "Richford", "Richmond Hill", "Richmondville", "Richville", "Ridge", "Ripley", "Riverhead", "Rochester", "Rock Hill", "Rock Tavern", "Rockaway Park", "Rockville Centre", "Rocky Point", "Rome", "Romulus", "Ronkonkoma", "Roosevelt", "Roscoe", "Rosedale", "Rosendale", "Roslyn", "Roslyn Heights", "Rotterdam Junction", "Round Top", "Rouses Point", "Roxbury", "Rush", "Rushford", "Rushville", "Rye", "Sackets Harbor", "Sag Harbor", "Sagaponack", "Saint Albans", "Saint Bonaventure", "Saint James", "Saint Johnsville", "Saint Regis Falls", "Salamanca", "Salem", "Salisbury Mills", "Salt Point", "Sanborn", "Sandy Creek", "Saranac Lake", "Saratoga Springs", "Saugerties", "Sauquoit", "Savannah", "Sayville", "Scarsdale", "Schaghticoke", "Schenectady", "Schenevus", "Schodack Landing", "Schoharie", "Schroon Lake", "Schuylerville", "Scio", "Scotia", "Scottsville", "Sea Cliff", "Seaford", "Selden", "Selkirk", "Seneca Falls", "Shandaken", "Shelter Island", "Shelter Island Heights", "Shenorock", "Sherburne", "Sheridan", "Sherman", "Sherrill", "Shirley", "Shokan", "Shoreham", "Shortsville", "Shrub Oak", "Sidney", "Sidney Center", "Silver Creek", "Silver Springs", "Sinclairville", "Skaneateles", "Skaneateles Falls", "Slate Hill", "Slaterville Springs", "Slingerlands", "Sloansville", "Sloatsburg", "Smallwood", "Smartville", "Smithtown", "Smithville Flats", "Smyrna", "Sodus", "Somers", "Sound Beach", "South Bethlehem", "South Butler", "South Dayton", "South Fallsburg", "South Glens Falls", "South Jamesport", "South Kortright", "South New Berlin", "South Otselic", "South Ozone Park", "South Plymouth", "South Salem", "Southampton", "Southfields", "Southold", "Sparkill", "Sparrow Bush", "Speculator", "Spencer", "Spencerport", "Spencertown", "Sprakers", "Spring Valley", "Springfield Gardens", "Springville", "Springwater", "Staatsburg", "Stamford", "Stanfordville", "Stanley", "Star Lake", "Staten Island", "Stephentown", "Sterling Forest", "Stillwater", "Stone Ridge", "Stony Brook", "Stony Creek", "Stony Point", "Stormville", "Strykersville", "Stuyvesant", "Stuyvesant Falls", "Suffern", "Sugar Loaf", "Sunnyside", "Sylvan Beach", "Syosset", "Syracuse", "Taberg", "Tappan", "Tarrytown", "The Bronx", "Thiells", "Thornwood", "Ticonderoga", "Tillson", "Tomkins Cove", "Tonawanda", "Treadwell", "Troy", "Trumansburg", "Truxton", "Tuckahoe", "Tully", "Tupper Lake", "Tuxedo Park", "Ulster Park", "Unadilla", "Union Springs", "Uniondale", "Unionville", "Upton", "Utica", "Vails Gate", "Valatie", "Valhalla", "Valley Cottage", "Valley Stream", "Van Etten", "Varysburg", "Verbank", "Vernon", "Vernon Center", "Verona", "Verona Beach", "Verplanck", "Vestal", "Victor", "Victory Mills", "Voorheesville", "Waccabuc", "Wading River", "Walden", "Wallkill", "Walton", "Walworth", "Wanakena", "Wantagh", "Wappingers Falls", "Warners", "Warrensburg", "Warsaw", "Warwick", "Washingtonville", "Wassaic", "Water Mill", "Waterford", "Waterloo", "Waterport", "Watertown", "Waterville", "Watervliet", "Watkins Glen", "Waverly", "Wayland", "Webster", "Weedsport", "Wells", "Wellsburg", "Wellsville", "West Babylon", "West Bloomfield", "West Chazy", "West Cornwall", "West Coxsackie", "West Edmeston", "West Falls", "West Haverstraw", "West Hempstead", "West Henrietta", "West Hurley", "West Islip", "West Leyden", "West Monroe", "West Nyack", "West Point", "West Sand Lake", "West Sayville", "West Somerset", "West Valley", "West Winfield", "Westbrookville", "Westbury", "Westerlo", "Westfield", "Westhampton", "Westhampton Beach", "Westons Mills", "Westport", "Westtown", "White Plains", "Whitehall", "Whitesboro", "Whitestone", "Whitesville", "Whitney Point", "Willet", "Williamson", "Williamstown", "Williston Park", "Willsboro", "Willseyville", "Wilmington", "Wilson", "Windsor", "Wingdale", "Winthrop", "Wolcott", "Woodbourne", "Woodbury", "Woodhaven", "Woodhull", "Woodmere", "Woodridge", "Woodside", "Woodstock", "Worcester", "Wurtsboro", "Wyandanch", "Wynantskill", "Wyoming", "Yaphank", "Yonkers", "York", "Yorktown Heights", "Youngstown", "Youngsville", "Yulan"]
How to we get city locality please give me any suggestion for asap.
I've freshly installed this gem and getting NoMethodError: undefined method
present?' for :US:Symbol`
if ! File.exists?
condition throws an error in the Ruby version later or equal 3.2.0
I was running it in Rails 7.0.4
and the Rails Console
suggests Did you mean? exist?
When executing CS.update
, I receive the following error:
No such file or directory @ rb_sysopen - https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&license_key=redacted&suffix=zip (Errno::ENOENT)
The update_maxmind
method is using OpenURI as just open()
, which is an override of Kernel#open
, but such use was deprecated in Ruby 2.7.
This was changed in OpenURI in Commit #0c2986a, roughly a year before the current v0.2.0 was released.
The solution here is to either:
URI.open()
instead of just open()
Hi,
I had to update the city-state gem to get the latest data. I ran CS.update from Rails console and checked the results. I got updated data but as soon as I close Rails console on Heroku, the changes were lost.
Am I missing a step here? Please provide some assistance ASAP.
Thank you.
Hi,
I can't find the city name Surat(in Gujrat, India) in this list.
Can you please look into it and do the needful?
Thanks,
Vikram
I am using Rails 5 and Bootstrap wth single_forn.
I am able to select the country correctly.
But when I am trying to select a state or a city I am getting only "Toshkent Shari" from Uzbekistan and no city no matter which country I selected.
It may be the case I an not using the right paratemetes in the form to be used by the two scripts I developed based on the models shown in this blog.
He are my application relevant files.
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
end
def states
render json: CS.states(params[:country]).to_json
end
def cities
render json: CS.cities(params[:state], params[:country]).to_json
end
end
routes.rb
Rails.application.routes.draw do
resources :contacts
root to: "application#index"
get 'states/:country', to: 'application#states'
get 'cities/:state', to: 'application#cities'
end
_form.rb
<%= simple_form_for(@contact) do |f| %>
<%= f.error_notification %>
<%= f.input :country, required: true, hint: 'select country', label: 'Country' do %>
<%= f.select :country,
CS.countries.map {|r| [r[1], r[0]] },
include_blank: false
%>
<% end %>
<%= f.input :state, required: true, hint: 'select state or province', label: 'State or Province' do %>
<%= f.select :state,
CS.states(params[:country]).map {|r| [r[1], r[0]] },
include_blank: false
%>
<% end %>
<%= f.input :city, required: true, hint: 'select city', label: 'City' do %>
<%= f.select :city,
CS.cities(params[:state], params[:country]).map {|r| [r]},
include_blank: false
%>
<% end %>
<%= f.input :address %>
<%= f.input :phone %>
<%= f.input :email %>
Due to the use of the simple_form the IDs of the elements in the DOM are "contact_country", "contact_state" and "contact_city"
Any help to fix this is much appreciated.
I am not getting any US cities.
[16] pry(main)> CS.cities(:us)
[]
[23] pry(main)> CS.cities(:ms)
[
[ 0] "Abbeville",
[ 1] "Aberdeen",
[ 2] "Ackerman",
[ 3] "Amory",
[ 4] "Anguilla",
[ 5] "Ashland",
[ 6] "Bailey",
............
First, thanks for this very useful gem!
Some countries seem to have no states, such as Anguilla (:AI). How can we get a list of cities of such countries?
Thank you.
Hey! I'm using this gem, going well so far. I needed to query cities with country name as compared to only being able to query cities with country code, so I've written a small method to do that. Take a look if you find it useful and think it should be merged. Thanks.
3.2.0 :002 > CS.countries
/home/valery/.local/share/gem/ruby/3.2.0/gems/city-state-0.1.0/lib/city-state.rb:286:in `countries': undefined
method `exists?' for File:Class (NoMethodError)
if ! File.exists? COUNTRIES_FN
^^^^^^^^
Did you mean? exist?
I was working on a project and came across this issue where i choose singapore as country and there are no states for that. So i was unable to access the cities for Singapore. So what's your take on this.
A number of us have to point at github in our Gemfiles to get fixes like this
MaxMind update their databases weekly on Tuesdays.
Since Dec 30, 2019, MaxMind requires a license key (for free) to get download updates.
To get the license key:
Sign up for a MaxMind account: https://www.maxmind.com/en/geolite2/signup
Create a license key: https://www.maxmind.com/en/accounts/current/license-key
There's no need to download anything.
To update.
CS.set_license_key('MY_KEY')
CS.update
and while doing this getting error of undefined method.
2.6.5 :002 > CS.set_license_key Traceback (most recent call last): 2: from (irb):2 1: from (irb):2:in
rescue in irb_binding'
NoMethodError (undefined method set_license_key' for CS:Module)
I will be working on the following features in Address Module.
The CSV pulled from MaxMind shows that several cities are available from Singapore. However those cities do not have a corresponding state which ended up excluded from the search list.
I was wondering if there are existing workarounds with this scenario. Is there a more future-proof way of dealing with a city without a state?
This gem seems to want to write files to its own gem directory. Is this normal? In production I get the following error and the Rails application won't boot:
Could not spawn process for application /var/www/spikeatschool/current: The application encountered the following error: Permission denied @ rb_sysopen - /var/www/xxxxxxxxxxxx/shared/bundle/ruby/2.6.0/gems/city-state-0.1.0/lib/db/states.nz (Errno::EACCES)
Is there a way to not have city-state
write these files? Perhaps just load them into memory instead?
Would it possible to add the feature for fetching the geolocation (lat and long) of selected country, state and city ?
We could fetch these using geocoder but it would be an unnecessary extra call. Also providers allow limited calls to their API's.
Hi, We have a request that Spain should use the more popular provinces, rather than the states in this gem. There are more provinces and apparently it is more useful information for what we are doing. We have a similar request for Hong Kong.
Is there some way for me to easily overwrite? I see in the lib/db folder a file called states_replace.yml
Was that put there for this purpose?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.