Controls empty response from geocoding service
This commit is contained in:
parent
048a5535dc
commit
1a21dda52a
@ -9,3 +9,7 @@ class BadGeocodingParams(Exception):
|
|||||||
class NoGeocodingParams(Exception):
|
class NoGeocodingParams(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr('No params for geocoding specified')
|
return repr('No params for geocoding specified')
|
||||||
|
|
||||||
|
class EmptyGeocoderResponse(Exception):
|
||||||
|
def __str__(self):
|
||||||
|
return repr('The request could not be geocoded')
|
||||||
|
@ -2,7 +2,7 @@ import inspect
|
|||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from heremapsexceptions import BadGeocodingParams, NoGeocodingParams
|
from heremapsexceptions import BadGeocodingParams, EmptyGeocoderResponse, NoGeocodingParams
|
||||||
|
|
||||||
class Geocoder:
|
class Geocoder:
|
||||||
'A Here Maps Geocoder wrapper for python'
|
'A Here Maps Geocoder wrapper for python'
|
||||||
@ -94,8 +94,12 @@ class Geocoder:
|
|||||||
|
|
||||||
return self.geocode(params)
|
return self.geocode(params)
|
||||||
|
|
||||||
def extractLngLatFromResponse(response):
|
def extractLngLatFromResponse(self, response):
|
||||||
location = response['Response']['View'][0]['Result'][0]['Location']
|
view = response['Response']['View']
|
||||||
|
|
||||||
|
if len(view) is 0: raise EmptyGeocoderResponse()
|
||||||
|
|
||||||
|
location = view[0]['Result'][0]['Location']
|
||||||
|
|
||||||
longitude = location['DisplayPosition']['Longitude']
|
longitude = location['DisplayPosition']['Longitude']
|
||||||
latitude = location['DisplayPosition']['Latitude']
|
latitude = location['DisplayPosition']['Latitude']
|
||||||
|
Loading…
Reference in New Issue
Block a user