I have received a JSON response after using the Reverse Geocoding API from Google. The response includes various address components such as route, sublocality, locality, and political information.
{
"results": [
{
"address_components": [
{
"long_name": "Goth Haji Umed Ali Gabole-Konker Road",
"short_name": "Goth Haji Umed Ali Gabole-Konker Rd",
"types": [
"route"
]
},
{
"long_name": "Haji Umaid Ali Goth",
"short_name": "Haji Umaid Ali Goth",
"types": [
"political",
"sublocality",
"sublocality_level_2"
]
},
{
"long_name": "Gadap",
"short_name": "Gadap",
"types": [
"political",
"sublocality",
"sublocality_level_1"
]
},
{
"long_name": "Karachi",
"short_name": "Karachi",
"types": [
"locality",
"political"
]
}
],
"status": "OK"}
Below is the code snippet:
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lng + "&key=AIzaSyBcV_CkYu5VvJb1ZZF8GWCAMyZhEDgpYzk";
jQuery.get(url, function (result)
{
console.log(result);
}
);
}
The JSON response can be viewed in the console. I am looking to extract the city name "Karachi". How can I achieve this?