InvalidPointException: 149.0639612 is not a valid latitude. Latitudes must lie between -90 and 90.
Closed this issue · 6 comments
Cross-posted from an issue raised by @ianweb1000:
Thanks for providing this function , i am new to gmaps i tried to used but failed on setting the lat and long when looking at the error it mention lat, long -90 to 90 , how do i set for another location? for example this case canberra? please see my code below..
import gmaps
import time
from IPython.display import display
gmaps.configure(api_key='AIzaSyDAe1GlPQ51-2cjZ-HRUpD4JVuIXXXXX')
Dummy data -- we will cycle through each of these on our heatmap.
datasets = [
[(149.0595142, -35.35740608), (149.0639612, -35.24647741)],
[(149.076662, -35.34001262), (149.0906542, -35.17645172), (149.1339467, -35.24790358)],
[(149.1324299, -35.21837069), (149.0626767, -35.31481163)],
[(149.1670283, -35.32215575), (149.1302218, -35.27727051), (149.1251359, -35.23272604)],
[(149.1262604, -35.3121351), (149.1434543, -35.33714495), (149.059198, -35.27239083)],
[(149.1251335, -35.27747377), (149.1774986, -35.32820705), (149.1689661, -35.3233789)],
[(149.1231831, -35.3052885), (149.1302284, -35.27426931), (149.1015366, -35.4612582)],
[(149.1958394, -35.23103345), (149.1244066, -35.30749543), (149.0857978, -35.33542881)],
]
class HeatmapAnimation(object):
def __init__(self, datasets):
self._datasets = datasets
self._figure = gmaps.figure(center=(-35.289, 149.130092), zoom_level=4)
self._current_index = 0
self._heatmap = gmaps.heatmap_layer(datasets[self._current_index])
self._figure.add_layer(self._heatmap)
def render(self):
return display(self._figure)
def start_animation(self):
while True:
self._current_index = (self._current_index + 1) % len(datasets)
self._render_current_dataset()
time.sleep(1)
def _render_current_dataset(self):
self._heatmap.locations = datasets[self._current_index] # update the locations drawn on the heatmap
animation = HeatmapAnimation(datasets)
animation.render()
animation.start_animation()
InvalidPointException: 149.0639612 is not a valid latitude. Latitudes must lie between -90 and 90.
Are latitude and longitudes the wrong way round in your dataset? gmaps
expects points to be (latitude, longitude), not (longitude, latitude).
Breaking your example down to a minimal reproducible example, I seem to get decent results by swapping the order.
import gmaps
import gmaps.datasets
gmaps.configure(api_key="AIzaS...")
# Latitudes and longitudes are the wrong way round:
dataset = [
(149.0595142, -35.35740608), (149.0639612, -35.24647741)
]
fig = gmaps.figure()
inverted_dataset = [(a, b) for (b, a) in dataset] # swap latitude and longitude round
symbols = gmaps.symbol_layer(inverted_dataset)
fig.add_layer(symbols)
fig
Well spotted. PRs welcome.
Closing this as presumably this was caused by having the latitudes and longitudes the wrong way around. Feel free to reopen if that isn't the case.