0

What is the most light weight method to allow users to select their city and country? I am aiming to make it so that the user begins to type their city and a limited number of suggestion pop up.

I have used typeahead.js and populated a variable with 247 countries on the client. But offering the entire worlds city list as well to the user is inefficient.

I have downloaded a json file that contains all the countries and their respective cities from https://github.com/David-Haim/CountriesToCitiesJSON/blob/master/countriesToCities.json

Considering this file to be 2MB in size, it is not significant for the functionality of my app so I dont want the client to download it all.

There is a good explanation on Importing a JSON file in Meteor on how to call the file from the server.

1) Where do I place the .json file to retrieve the file from the server via a http call? There is a lib in root directory but it can also be placed in server>lib>

Community
  • 1
  • 1
meteorBuzz
  • 3,110
  • 5
  • 33
  • 60

1 Answers1

1

The leanest way would be use the native Meteor autocomplete package and populate a collection with the cities from the JSON file via mongoimport --type json

Check out the demos at http://autocomplete.meteor.com.

Meteor's DDP protocol is more efficient and simpler than the old-school REST style of data transfer. With the autocomplete package, you won't even need to write any code actually.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • I have realised when the user is inserting their publication location, it will be their business address. I guess I will have to use some API. So I might as well use the API for the city and country location as well. I will edit my question – meteorBuzz Dec 10 '14 at 09:45
  • 1
    @CodeCandy: Google's [Places autocomplete API](https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform) is very easy to use. – Dan Dascalescu Dec 10 '14 at 19:38