0

I want to get a list of cities that lie between cities A and B. I am using Google Maps API. On searching, I found a similar question on SO,

Is it possible to get list of City between City A and City B in Google Maps

Here, solution that was suggested is reverse geocoding. There is another similar question :

How to get places between give two city using Google Map API

Both the solutions are not clear as how they can be applied to solve the problem stated. Can anyone please explain the approach to be used in steps or any already available example on the web known to you.

Thanks a lot.

Community
  • 1
  • 1
Naveen
  • 7,944
  • 12
  • 78
  • 165

1 Answers1

2

What those solutions say is that there is no way to do it directly using Google Maps API. What you can do instead is:

  1. Define what between exactly means(something like a line on a sphere connecting cities A and B).

  2. Choose a bunch of points between these cities(if "between" means a line segment on a sphere, you can divide it into several small segments and pick their end points).

  3. Use reverse geocoding for each of the selected points in step 2 to check if it lies inside any city. If it does, add this city to the result set.

  4. Return the result set.

Another approach(if your are interested in a fixed subset of all cities in the world) is to pick each city from the "interesting" set, get its geolocation and check if it lies between A and B(again, you need to define what between means exactly).

kraskevich
  • 18,368
  • 4
  • 33
  • 45
  • It's non-trivial to find a good heuristic for this in order to perform well. And it all depends on what you mean with "in between" as you already stated. Good answer! I was ready for answering this one when something else needed my attention and when I returned you already gave the answer I could have written. Well done! – Youp Bernoulli Jan 03 '15 at 12:54
  • Thanks kraskevich, great idea. – Anand Suthar Jul 03 '18 at 07:30
  • @AnandSuthar Did you find out any solution for your question? I'm also stuck with same – dilipkumar1007 Jan 10 '23 at 06:57