0

I have a multi-language web site. On the web site, users can search products and services by geographic areas.

I am asking which is best approach to performs search of geographic areas. In this moment I am using geographic coordinates.

I stored in my database the boundaries of different areas, then when user input a city (for example) on the web site, I make a request to Google, I obtain coordinates, then I search if the coordinates retrieved by Google are within the boundaries I previously loaded on database.

This approach has some pros but also different cons.

PRO

  1. I do not care about language. Users input cities. I call google. Google give me coordinates. Then I make the search on coordinates;

CONS

  1. I must search boundaries of the regions e then store it on my database. Not always it is easy find free or detailed boundaries;
  2. Often different users input same cities more and more times. This means I call repeatedly Google to obtain alwais the same coordiantes. Google has a cost I cannot effort in this moment. But I found it is the most accurate service.

What I would like is remove dependencies from google.

I think I should store the cities, provinces, regions and countries all over the world in my database. Then make searches on the name. But name can change according to language (for example Paris, Parigi, Paryz, Parizh... ). So perhaps that is not the most correct way to performs research.

I am not looking for a solution language-based. But it is purely theory. What do you suggest?

Thank you

Simone
  • 127
  • 2

1 Answers1

2

Caching the data looks like the way to go indeed. Different names for the same city is not a problem, you will get duplicate values in your database but they will be independent. I would also store failure ids (if you pay for requests that do not yield anything useful) so you will not needlessly perform those calls again. Your costs should soon go down as your database fills up.

As a poor man's solution you could pre-enter coordinates for major cities and store square regions for those with a size proportional to the number of inhabitants. Then always return the region of the nearest city in response to whatever a use enters.

Martin Maat
  • 18,218
  • 3
  • 30
  • 57
  • Yes, your answer solve me first problem. But the second is the search: should I pre-fill up the database with the boundaries of all the cities? For example. User look for a product/service in Paris. I get the coordinates of Paris (from database or google). Then I look for if those coordinates are inside the pre-loaded boundaries. I see 2 problems (?): I should find all the boundaries and perhaps thesearchon boundaries is really heavy (?). – Simone May 04 '20 at 05:14
  • @Ciccio I did one search and found this: https://simplemaps.com/data/world-cities You can get lat, lon and population on all major cities for free here. You do not store regions if you use squares of course, you just calculate the square every time you need it from those three numbers. – Martin Maat May 04 '20 at 06:08