Geocoding: Inconsistency of coordinate’s order between Google maps and D3.

My conclusion:

D3.js seems to take coordinate as [longitude,latitude]; Google maps takes  [latitude,longitude].
The list format including a comma, like [n,n], is not suit for csv files, because csv deal with comma as separator.
Whether it is csv or JSON, latitude and longitude should be stored independently, with annotation.

 

Context:
In this week, I was trying to make geolocation data of whole Japanese listed companies, and I had finished it successfully. I am going to put the data on a data storage page on my blog. But during this effort, I stacked at some point. The most thing that took me almost an hours, is coordination problem. The order of coordinate, latitude and longitude, seems to be different between Google maps and D3!

Geocoding is the effort to get a location data which is based on the Earh’s latitude and longitude. Google maps API helps us the task. For example, it take a company’s address, then turns into the geological coordinate data, like 1. Lists don’t have annotation, and  that was the source of the problem.

 

The different order of coordinate:

My coordinate data came from Google maps API, by python’s library “geocoder”. Then I was trying to render a Japanese map and the companies on it, byJavascript library, D3.js. But it caused insistent errors in my project.

The reason is, d3.geo.albers() takes a coordinate as [longitude,latitude], but Google maps API and even Google map’s search take a coordinate data in the order [latitude,longitude].

 

The list has more problems:

The coordinate lists raised more problems. The major file format, csv takes comma as separator, so that the [n,n] list are separated at the center, or wrapped with double quotes like “[n,n]”. In each case, some tedious works would happen in converting into JSON file and reading file to Javascript code — You may have to replace double quote or change data type, or use regular expression.

 

So what should I do with it? I recommend you store latitude and longitude in separate columns or dictionaries. Then when you import the data, insert both of data into [].

 

  1. 6626569, 139.7692035″,1352
One Comment

Leave a Reply