How to find the full address by postcode or longitude and lattitude of the place?
We can get the full address by postcode like city, state, country, etc by passing postcode or longitude and lattitude. To get the full address by postcode or longitude and lattitude we have to specify a google url with API key.
If you dont have API key don’t worry just visit Google Console this link and generate a new API key. For the first year it will be absolutely free.
Here we are using cUrl for the API, because it is widely used because of its ability to be flexible and complete complex tasks. For example, you can use curl for things like user authentication, HTTP post, SSL connections, proxy support, FTP uploads, and more! You can also do simple things with curl, such as download web pages and web images.
cURL
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://maps.googleapis.com/maps/api/geocode/json?address=560035&key=YOUR_API_KEY",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
By Pincode/Zipcode :
https://maps.googleapis.com/maps/api/geocode/json?address=560035&key=YOUR_API_KEY
Result :
{
"results": [
{
"address_components": [
{
"long_name": "560035",
"short_name": "560035",
"types": [
"postal_code"
]
},
{
"long_name": "Bengaluru",
"short_name": "Bengaluru",
"types": [
"locality",
"political"
]
},
{
"long_name": "Bangalore Urban",
"short_name": "Bangalore Urban",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Karnataka",
"short_name": "KA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "India",
"short_name": "IN",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Bengaluru, Karnataka 560035, India",
"geometry": {
"bounds": {
"northeast": {
"lat": 12.9209007,
"lng": 77.70799939999999
},
"southwest": {
"lat": 12.8810011,
"lng": 77.6671992
}
},
"location": {
"lat": 12.9048022,
"lng": 77.68210689999999
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 12.9209007,
"lng": 77.70799939999999
},
"southwest": {
"lat": 12.8810011,
"lng": 77.6671992
}
}
},
"place_id": "ChIJKX8J1jwTrjsR7XGMHKeSqr8",
"types": [
"postal_code"
]
}
],
"status": "OK"
}
By Lattitude and Longitude
https://maps.googleapis.com/maps/api/geocode/json?address=12.9538477,77.3507323&key=YOUR_API_KEY
Result :
{
"results": [
{
"address_components": [
{
"long_name": "Unnamed Road",
"short_name": "Unnamed Road",
"types": [
"route"
]
},
{
"long_name": "Bangalore Urban",
"short_name": "Bangalore Urban",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Karnataka",
"short_name": "KA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "India",
"short_name": "IN",
"types": [
"country",
"political"
]
},
{
"long_name": "562130",
"short_name": "562130",
"types": [
"postal_code"
]
}
],
"formatted_address": "Unnamed Road, Karnataka 562130, India",
"geometry": {
"bounds": {
"northeast": {
"lat": 12.9530967,
"lng": 77.3531921
},
"southwest": {
"lat": 12.9523544,
"lng": 77.3509229
}
},
"location": {
"lat": 12.952648,
"lng": 77.35211550000001
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"northeast": {
"lat": 12.9540745302915,
"lng": 77.35340648029151
},
"southwest": {
"lat": 12.9513765697085,
"lng": 77.3507085197085
}
}
},
"place_id": "ChIJ4wsEATU3rjsRjEFs68qyf40",
"types": [
"route"
]
},
{
"address_components": [
{
"long_name": "562130",
"short_name": "562130",
"types": [
"postal_code"
]
},
{
"long_name": "Karnataka",
"short_name": "KA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "India",
"short_name": "IN",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Karnataka 562130, India",
"geometry": {
"bounds": {
"northeast": {
"lat": 13.0114028,
"lng": 77.4713912
},
"southwest": {
"lat": 12.8541056,
"lng": 77.3346998
}
},
"location": {
"lat": 12.9459719,
"lng": 77.3898602
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 13.0114028,
"lng": 77.4713912
},
"southwest": {
"lat": 12.8541056,
"lng": 77.3346998
}
}
},
"place_id": "ChIJ93gSob85rjsRbqiRG5ShiAA",
"types": [
"postal_code"
]
},
{
"address_components": [
{
"long_name": "Bangalore Urban",
"short_name": "Bangalore Urban",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Karnataka",
"short_name": "KA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "India",
"short_name": "IN",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Bangalore Urban, Karnataka, India",
"geometry": {
"bounds": {
"northeast": {
"lat": 13.22497,
"lng": 77.83501
},
"southwest": {
"lat": 12.65785,
"lng": 77.32867
}
},
"location": {
"lat": 12.9700247,
"lng": 77.65361249999999
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 13.22497,
"lng": 77.83501
},
"southwest": {
"lat": 12.65785,
"lng": 77.32867
}
}
},
"place_id": "ChIJ_Q7NCkQWrjsRn2yP7O-T8Fg",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"address_components": [
{
"long_name": "Karnataka",
"short_name": "KA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "India",
"short_name": "IN",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Karnataka, India",
"geometry": {
"bounds": {
"northeast": {
"lat": 18.4411689,
"lng": 78.5881402
},
"southwest": {
"lat": 11.593352,
"lng": 74.04960609999999
}
},
"location": {
"lat": 15.3172775,
"lng": 75.7138884
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 18.4411689,
"lng": 78.5881402
},
"southwest": {
"lat": 11.593352,
"lng": 74.04960609999999
}
}
},
"place_id": "ChIJj0i_N0xaozsR1Xx10YzS8UE",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"address_components": [
{
"long_name": "India",
"short_name": "IN",
"types": [
"country",
"political"
]
}
],
"formatted_address": "India",
"geometry": {
"bounds": {
"northeast": {
"lat": 35.513327,
"lng": 97.39535869999999
},
"southwest": {
"lat": 6.4626999,
"lng": 68.1097
}
},
"location": {
"lat": 20.593684,
"lng": 78.96288
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 35.513327,
"lng": 97.39535869999999
},
"southwest": {
"lat": 6.4626999,
"lng": 68.1097
}
}
},
"place_id": "ChIJkbeSa_BfYzARphNChaFPjNc",
"types": [
"country",
"political"
]
}
],
"status": "OK"
}
The final result for full address by postcode or longitude and lattitude will return us each and everything like road name,place id even country id, etc.
For any php related solutions please visit Php
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/kz/register?ref=T7KCZASX