How to Solve the 180th Meridian Issue
What is the 180th Meridian?
The 180th meridian is the geographical boundary between the Eastern and Western hemispheres. It passes through the Pacific Ocean as well as parts of Russia, Alaska, and the Fiji islands. The Geo Search API has a problem with any bounded area that includes the 180th meridian.
The issue is that if you allow users to include the 180th meridian within a rectangle or polygon area, the selected area will not match the results you get. In fact, the results will give you everything outside of the area that you selected.
That’s because the longitudinal numbers, at the 180th meridian, become negative numbers (from 180 to -180 instead of 181). And this causes the API to calculate the wrong area: the API assumes that the lowest longitudinal number is always the most westerly, but in this case the easterly numbers are lower because they are negative. So, while the API is correct for most of the world, it is not correct when you cross the 180th meridian.
The recommended workaround is to use the union of two adjacent rectangles around the meridian. For example, instead of setting insideBoundingBox to
[70, 170, 60, -170], you would pass
[[70, 170, 60, 180], [70, -180, 60, -170]].
This method also applies to insidePolygon, where you will likewise need to separate the polygon area into 2 series of coordinates:
- series 1 will contain the area to the east of the meridian
- series 2 will contain the remaining area, west of the meridian.
In other words, whenever your border crosses the meridian, you will need to use 2 series to define an area.