Last active
May 17, 2018 12:01
-
-
Save persidskiy/5788975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getHumanAddress(geoObject){ | |
var declaration = { | |
'CountryName': 'country', | |
'AdministrativeAreaName': 'area', | |
'SubAdministrativeAreaName': 'subarea', | |
'LocalityName': 'city', | |
'DependentLocalityName': 'subcity', | |
'ThoroughfareName': 'street', | |
'PremiseNumber': 'house' | |
} | |
,parseParams = ['Country', 'CountryName', 'AdministrativeArea', 'AdministrativeAreaName', | |
'Locality', 'LocalityName', 'Thoroughfare', 'ThoroughfareName', 'Premise', 'PremiseNumber', | |
'DependentLocality', 'DependentLocalityName', | |
'SubAdministrativeArea', 'SubAdministrativeAreaName'] | |
,level = geoObject['metaDataProperty']['GeocoderMetaData']['AddressDetails'] | |
,result={} | |
,nextLevel; | |
while(1){ | |
var goDeeper = false; | |
for(var key in level){ | |
if(parseParams.indexOf(key)!==-1){ | |
if(typeof level[key] === 'object'){ | |
nextLevel = level[key]; | |
goDeeper = true; | |
}else{ | |
for(var declKey in declaration){ | |
if(declKey === key){ | |
result[declaration[key]] = level[key]; | |
} | |
} | |
} | |
} | |
} | |
if(goDeeper){ | |
level = nextLevel; //we need to go deeper ;) | |
}else{ | |
break; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Парсер уже есть в самом АПИ