Skip to content

Commit 9080208

Browse files
authored
Merge pull request #138 from JacobGeoGeek/bug-137-No-data-validation-lat-lng
Validate the lat lng coordinates when initialize the Map object.
2 parents c0aa16a + 86ea52d commit 9080208

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

flask_googlemaps/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
self.language = language
6060
self.region = region
6161
self.varname = varname
62-
self.center = (lat, lng)
62+
self.center = self.verify_lat_lng_coordinates(lat, lng)
6363
self.zoom = zoom
6464
self.maptype = maptype
6565
self.markers = []
@@ -758,6 +758,14 @@ def as_json(self):
758758

759759
return json_dict
760760

761+
def verify_lat_lng_coordinates(self, lat, lng):
762+
if not (90 >= lat >= -90):
763+
raise AttributeError("Latitude must be between -90 and 90 degrees inclusive.")
764+
if not (180 >= lng >= -180):
765+
raise AttributeError("Longitude must be between -180 and 180 degrees inclusive.")
766+
767+
return (lat,lng)
768+
761769
@property
762770
def js(self):
763771
return Markup(

0 commit comments

Comments
 (0)