Search code examples
google-mapsgoogle-maps-api-3google-distancematrix-api

Google Distance Matrix Not Returning Rail Results for East Asian Cities


I'm building a tool to understand levels of transport connectivity between major cities in 'global mega-regions'. It's pretty straightforward - we enter a bunch of cities into Googles distance matrix and Google in turn tells us transit times.

The code works perfectly fine for European and American cities. However, there seems to be some issue with East Asian cities (China and Japan). Google is either returning no result, or it is returning substantially longer transit times than are correct when compared to a search on Google maps itself.

Upon further investigation, it appears that the Google Distance Matrix API will not return any rail results for East Asian cities (only bus routes - if they exist). This is despite those rail routes showing up on Google Maps.

x = gmaps.distance_matrix(
      ['Kyoto, Japan'],
      ['Osaka, Japan'],
      mode='transit',
      units='metric' )
x

Which returns:

{'destination_addresses': ['Osaka, Japan'],
 'origin_addresses': ['Kyoto, Japan'],
 'rows': [{'elements': [{'status': 'ZERO_RESULTS'}]}],
 'status': 'OK'}

However, as you can see in the image below, there are numerous perfectly suitable routes.

Image of Google Maps results via maps.google.com

Just to let you know what I have tried so far:

  • Enforcing a preference for train transit_mode.
  • Altering the departure time
  • Running the code as a standard URL request rather than via the Python library
  • Tried longitude/latitudes rather than city names.

Thanks in advance


Solution

  • This official documentation page mentions that:

    In which countries are transit directions available?

    The Google Maps Directions Service, which includes the Directions API and Distance Matrix API, supports all the transit providers in the transit coverage list, except for those in Japan.

    This doesn't give any information about why it is so, but apparently it simply doesn't support TRANSIT mode directions in Japan.


    As for China, and although many Chinese cities are listed in the transit coverage list, it is also mentioned that:

    Maps APIs may not be used in Prohibited Territories.

    And China is one of them.

    I must admit that regarding China it is not always clear. You may want to contact Google Support directly if you need more information and/or expand your question with some examples.