Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3699468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:06:23+00:00 2026-05-19T05:06:23+00:00

i need to retrieve all the city names from a specific country using openstreet

  • 0

i need to retrieve all the city names from a specific country using openstreet map or google maps. is there any API available?

or is there any other way of getting this world geographic data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T05:06:23+00:00Added an answer on May 19, 2026 at 5:06 am

    You should definitely checkout GeoNames. They have the entire world in a standardized database. You can download it or use their API.

    I download the US database and use a connector I created in C# to insert States, Cities, Towns, and Zip Codes in my database.

        public static class GeoNamesConnector
    {
        #region GeoName Constants
        private static readonly string GeoNamesPath = HttpContext.Current.Server.MapPath("~/App_Data/GeoNames/US.txt");
        const int GeoNameIdColumn = 0;
        const int NameColumn = 1;
        const int LatitudeColumn = 4;
        const int LongitudeColumn = 5;
        const int FeatureCodeColumn = 7;
        const int CountryCodeColumn = 8;
        const int Admin1CodeColumn = 10;
        const int Admin2CodeColumn = 11;
        #endregion
    
        #region AlternateName Constants
        private static readonly string AlternateNamesPath = HttpContext.Current.Server.MapPath("~/App_Data/GeoNames/alternateNames.txt");
        const int AlternateNameIdColumn = 0;
        const int AltNameGeoNameIdColumn = 1;
        const int IsoLanguageColumn = 2;
        const int AlternateNameColumn = 3;
        #endregion
    
        public static void AddAllEntities(GeoNamesEntities entities)
        {
            //Remember to turn off Intellitrace
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            var geoNamesSortedList = AddGeoNames(entities);
            Trace.WriteLine(String.Format("Added GeoNames: {0}", stopwatch.Elapsed));
            stopwatch.Restart();
    
            SetupGeoNameChildRelationships(geoNamesSortedList, entities);
            Trace.WriteLine(String.Format("Setup GeoName parent/child relationships: {0}", stopwatch.Elapsed));
            stopwatch.Restart();
    
            AddPostalCodeAlternateNames(geoNamesSortedList, entities);
            Trace.WriteLine(String.Format("Added postal codes and relationships with parent GeoNames: {0}", stopwatch.Elapsed));
        }
    
        private static SortedList<int, GeoName> AddGeoNames(GeoNamesEntities entities)
        {
            var lineReader = File.ReadLines(GeoNamesPath);
            var geoNames = from line in lineReader.AsParallel()
                           let fields = line.Split(new char[] { '\t' })
                           let fieldCount = fields.Length
                           where fieldCount >= 9
                           let featureCode = fields[FeatureCodeColumn]
                           where featureCode == "ADM1" || featureCode == "ADM2" || featureCode == "PPL"
                           let name = fields[NameColumn]
                           let id = string.IsNullOrEmpty(fields[GeoNameIdColumn]) ? 0 : int.Parse(fields[GeoNameIdColumn])
                           orderby id
                           select new GeoName
                           {
                               Id = Guid.NewGuid(),
                               GeoNameId = id,
                               Name = fields[NameColumn],
                               Latitude = string.IsNullOrEmpty(fields[LatitudeColumn]) ? 0 : Convert.ToDecimal(fields[LatitudeColumn]),
                               Longitude = string.IsNullOrEmpty(fields[LongitudeColumn]) ? 0 : Convert.ToDecimal(fields[LongitudeColumn]),
                               FeatureCode = featureCode,
                               CountryCode = fields[CountryCodeColumn],
                               Admin1Code = fieldCount < 11 ? "" : fields[Admin1CodeColumn],
                               Admin2Code = fieldCount < 12 ? "" : fields[Admin2CodeColumn]
                           };
            var sortedList = new SortedList<int, GeoName>();
            int i = 1;
            foreach (var geoname in geoNames)
            {
                sortedList.Add(geoname.GeoNameId, geoname);
                entities.GeographicAreas.AddObject(geoname);
                if (i++ % 20000 == 0)
                    entities.SaveChanges();
            }
            entities.SaveChanges();
            return sortedList;
        }
    
        private static void SetupGeoNameChildRelationships(SortedList<int, GeoName> geoNamesSortedList, GeoNamesEntities entities)
        {
            foreach (var geoName in geoNamesSortedList.Where(g => g.Value.FeatureCode == "ADM2" || g.Value.FeatureCode == "ADM1"))
            {
                //Setup parent child relationship
                IEnumerable<KeyValuePair<int, GeoName>> children = null;
                switch (geoName.Value.FeatureCode)
                {
                    case "ADM1":
                        children =
                            geoNamesSortedList.Where(
                                g =>
                                g.Value.FeatureCode == "ADM2" &&
                                g.Value.Admin1Code == geoName.Value.Admin1Code);
                        break;
                    case "ADM2":
                        children =
                            geoNamesSortedList.Where(
                                g =>
                                g.Value.FeatureCode == "PPL" &&
                                g.Value.Admin1Code == geoName.Value.Admin1Code &&
                                g.Value.Admin2Code == geoName.Value.Admin2Code);
                        break;
                }
                if (children != null)
                {
                    foreach (var child in children)
                        geoName.Value.Children.Add(child.Value);
                }
                entities.SaveChanges();
            }
        }
    
        private static void AddPostalCodeAlternateNames(SortedList<int, GeoName> geoNamesSortedList, GeoNamesEntities entities)
        {
            var lineReader = File.ReadLines(AlternateNamesPath);
            var alternativeNames = from line in lineReader.AsParallel()
                                   let fields = line.Split(new char[] { '\t' })
                                   let fieldCount = fields.Length
                                   where fieldCount >= 4 && fields[IsoLanguageColumn] == "post"
                                   let geoNameId = int.Parse(fields[AltNameGeoNameIdColumn])
                                   orderby geoNameId
                                   select new AlternateName
                                   {
                                       Id = Guid.NewGuid(),
                                       AlternateNameId = int.Parse(fields[AlternateNameIdColumn]),
                                       ParentGeoNameId = geoNameId,
                                       Name = fields[AlternateNameColumn],
                                       IsoLanguage = fields[IsoLanguageColumn]
                                   };
            //Iterate through to convert from lazy (AsParallel) so it is ready for use
            foreach (var alternateName in alternativeNames)
            {
                int key = alternateName.ParentGeoNameId;
                if (geoNamesSortedList.ContainsKey(key))
                {
                    entities.GeographicAreas.AddObject(alternateName);
                    alternateName.Parent = geoNamesSortedList[key];
                }
            }
            entities.SaveChanges();
        }
    
    }
    

    There is also Open Street Maps that you can download or use their API.

    I do not suggest Yahoo’s new API they are cutting products left and right and you never know how long it will be around. Also you cannot download a whole dump currently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve all commits from all branches. I retrieve them using command:
Hi I'm new to Oracle 10g. I need retrieve the all the sublist from
i need to retrieve the page title from an URL i already have using
I need to retrieve all rows from a table where 2 columns combined are
I need to retrieve all Organizational Units from a given DN stringh, I am
I'm using the GitHub Developer API v2. Currently need to retrieve all the file
If there are two separate strings, we need to retrieve all words that are
I have need to retrieve all of the items in a Datagrid from an
I need to retrieve all items from two lists that contains a given value.
I need to retrieve all information about records that are duplicates for specific fields.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.