---
title: "How to get Latitude/Longitude from an address (or Geocoding ) using PHP"
url: https://thecancerus.com/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/
date: 2010-03-10
modified: 2010-03-10
author: "ican"
description: "While Google’s documents for maps API does good job in showing how to get lat/long from an address in JavaScript they do not really show any example of doing the..."
categories:
  - "how too?"
  - "php"
word_count: 108
---

# How to get Latitude/Longitude from an address (or Geocoding ) using PHP

While Google’s documents for maps API does good job in showing how to get lat/long from an address in JavaScript they do not really show any example of doing the same with PHP.

 

So to make you life simple here is a small script in PHP that does that.

 

 

$geocode=file_get_contents('[http://maps.google.com/maps/api/geocode/json?address=573/1,+Jangli+Maharaj+Road,+Deccan+Gymkhana,+Pune,+Maharashtra,+India&sensor=false');](http://maps.google.com/maps/api/geocode/json?address=573/1,+Jangli+Maharaj+Road,+Deccan+Gymkhana,+Pune,+Maharashtra,+India&sensor=false)

$output= json_decode($geocode);

$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;

 

The line above makes a request to Google maps API. Passes the address, and receives the response in JSON format.

The URL has following options

[http://maps.google.com/maps/api/geocode/*output*?*parameters](http://maps.google.com/maps/api/geocode/output?parameters)*

where *output* can be 1) JSON or 2) XML

For more details about parameters check out the [Google’s geocoding documentation](http://code.google.com/apis/maps/documentation/geocoding/index.html).