Deprecated: Function create_function() is deprecated in /home/ursaftwz/public_html/myscripthub.com/wp-content/plugins/codecolorer/lib/geshi.php on line 4698

Get Latitude/Longitude From an Address with Google Map

This is the process of converting addresses (like “201 S. Division St., Ann Arbor, MI 48104”) into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers on a map, or position the map.

1
2
3
4
5
6
7
8
9
10
11
12
  $address = '201 S. Division St., Ann Arbor, MI 48104';

$prepAddr = str_replace(' ','+',$address);

$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');

$output= json_decode($geocode);

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

echo $address.'Lat: '.$lat.'Long: '.$long;

Leave a Reply