Skip to content

Instantly share code, notes, and snippets.

@madeinnordeste
Last active January 13, 2025 14:31
Show Gist options
  • Save madeinnordeste/3250820 to your computer and use it in GitHub Desktop.
Save madeinnordeste/3250820 to your computer and use it in GitHub Desktop.
PHP - Get Geocode (lat, long) from Address
<?php
$address = 'avenida+gustavo+paiva,maceio,alagoas,brasil';
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$address.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
?>
@bagastone
Copy link

i get some error for this code. can you help me please

Notice: Undefined offset: 0 in C:\xampp\htdocs\maps\index.php on line 10
Notice: Trying to get property of non-object in C:\xampp\htdocs\maps\index.php on line 10
Notice: Trying to get property of non-object in C:\xampp\htdocs\maps\index.php on line 10
Notice: Trying to get property of non-object in C:\xampp\htdocs\maps\index.php on line 10
Notice: Undefined offset: 0 in C:\xampp\htdocs\maps\index.php on line 11
Notice: Trying to get property of non-object in C:\xampp\htdocs\maps\index.php on line 11
Notice: Trying to get property of non-object in C:\xampp\htdocs\maps\index.php on line 11
Notice: Trying to get property of non-object in C:\xampp\htdocs\maps\index.php on line 11

@shamiul700
Copy link

Now It require api key.
Is there any Way to get lat long from address for free?

@RaccoonCast
Copy link

Now It require api key.
Is there any Way to get lat long from address for free?

Use OSM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment