Last active
December 18, 2015 18:19
-
-
Save mborodov/5824408 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 getGoogleGeoTag(lat,lng) { | |
$.get("http://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat +"," + lng + | |
"&sensor=false&language=ru",function(data) { | |
// Define address array for short | |
var address_array = data.results[0].address_components; | |
// Define finish substrings | |
var country =""; | |
var city = ""; | |
var street = ""; | |
// Find substrings | |
for (address_key in address_array) { | |
if (address_array[address_key].types[0] == "country") { | |
country = address_array[address_key].long_name; | |
} | |
if (address_array[address_key].types[0] == "locality") { | |
city = address_array[address_key].long_name; | |
} | |
if (address_array[address_key].types[0] == "route") { | |
street = address_array[address_key].long_name; | |
} | |
} | |
// Join substring in finish string | |
var geoString = street+", "+city+", "+country; | |
return geoString; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
need jquery for Ajax request