Write non Latin geolocation data if only non latin one is found
In case only non Latin geo location data is found, the first match will be used to replace the not found Latin entry
This commit is contained in:
@@ -190,6 +190,7 @@ def reverseGeolocateOpenStreetMap(longitude, latitude):
|
|||||||
def reverseGeolocateGoogle(longitude, latitude):
|
def reverseGeolocateGoogle(longitude, latitude):
|
||||||
# init
|
# init
|
||||||
geolocation = reverseGeolocateInit(longitude, latitude)
|
geolocation = reverseGeolocateInit(longitude, latitude)
|
||||||
|
temp_geolocation = geolocation.copy()
|
||||||
if geolocation['status'] == 'ERROR':
|
if geolocation['status'] == 'ERROR':
|
||||||
return geolocation
|
return geolocation
|
||||||
# sensor (why?)
|
# sensor (why?)
|
||||||
@@ -250,15 +251,24 @@ def reverseGeolocateGoogle(longitude, latitude):
|
|||||||
# this is an array, so we need to loop through each
|
# this is an array, so we need to loop through each
|
||||||
for addr in entry['address_components']:
|
for addr in entry['address_components']:
|
||||||
# in types check that index is in there and the location is not yet set
|
# in types check that index is in there and the location is not yet set
|
||||||
# also check that entry is NOT in japanese
|
# also check that entry is in LATIN based
|
||||||
|
# NOTE: fallback if all are non LATIN?
|
||||||
if index in addr['types'] and not geolocation[loc_index]:
|
if index in addr['types'] and not geolocation[loc_index]:
|
||||||
# for country code we need to use short name, else we use long name
|
# for country code we need to use short name, else we use long name
|
||||||
if loc_index == 'CountryCode':
|
if loc_index == 'CountryCode':
|
||||||
if onlyLatinChars(addr['short_name']):
|
if onlyLatinChars(addr['short_name']):
|
||||||
geolocation[loc_index] = addr['short_name']
|
geolocation[loc_index] = addr['short_name']
|
||||||
|
elif not temp_geolocation[loc_index]:
|
||||||
|
temp_geolocation[loc_index] = addr['short_name']
|
||||||
else:
|
else:
|
||||||
if onlyLatinChars(addr['long_name']):
|
if onlyLatinChars(addr['long_name']):
|
||||||
geolocation[loc_index] = addr['long_name']
|
geolocation[loc_index] = addr['long_name']
|
||||||
|
elif not temp_geolocation[loc_index]:
|
||||||
|
temp_geolocation[loc_index] = addr['long_name']
|
||||||
|
# check that all in geoloaction are filled and if not fille from temp_geolocation dictionary
|
||||||
|
for loc_index in type_map:
|
||||||
|
if not geolocation[loc_index] and temp_geolocation[loc_index]:
|
||||||
|
geolocation[loc_index] = temp_geolocation[loc_index]
|
||||||
# write OK status
|
# write OK status
|
||||||
geolocation['status'] = response.json()['status']
|
geolocation['status'] = response.json()['status']
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user