Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily instantiate geocoder #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions cesiumpy/extension/geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@

import cesiumpy.util.common as com

# ToDo: want different geocoders?
_GEOCODER = GoogleV3()
_GEOCODER = None


def _get_geocoder():
global _GEOCODER
if _GEOCODER is None:
# ToDo: want different geocoders?
_GEOCODER = GoogleV3()
return _GEOCODER


def _maybe_geocode(x, height=None):
Expand All @@ -18,7 +25,7 @@ def _maybe_geocode(x, height=None):
height can be used to create base data for Cartesian3
"""
if isinstance(x, six.string_types):
loc = _GEOCODER.geocode(x)
loc = _get_geocoder().geocode(x)
if loc is not None:
if height is None:
# return x, y order
Expand Down