Skip to content

Instantly share code, notes, and snippets.

@persidskiy
Last active May 17, 2018 12:01
Show Gist options
  • Save persidskiy/5788975 to your computer and use it in GitHub Desktop.
Save persidskiy/5788975 to your computer and use it in GitHub Desktop.
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;
}
@maxner
Copy link

maxner commented Nov 13, 2017

Огромное спасибо!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment