TIP: Invalid Longitude numbers and OpenWeatherMap

Guys, fair warning… if you pass to OpenWeatherMap Longitude numbers that are less than -180, or more than 180, OWM doesn’t know what to do and gives you an error 400 and no data.

I discovered this when I get my Lat/Lng numbers from Google Maps… when you drag Google Maps (drag pan left or right), Google Maps will give Lng numbers that are less than -180 depending on how far you drag the map from it’s original location! And when you pass something like -220.9093 to OpenWeatherMap, well, you get an error.

So before passing the Longitude number to OWM, do some checking.

    function translateLongitude(lng){
      if (lng < -180){
        lng = lng + 360;
      } else if (lng > 180) {
        lng = lng - 360;
      return lng;

can it be because it’s an impossible scenario?

Impossible, you would think. I know Lng valid range is +/-180.

Don’t know why Google maps return Lng values > 180 or <-180 when you drag their interactive map, and then query the new center lat/lng position.

See above. lat/lon values came from Google maps API (after generating initial map, then dragging map from initial position and panning right)

Thus proving that Google Earth is in a mirror universe.