-
-
Save madeinnordeste/3250820 to your computer and use it in GitHub Desktop.
<?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; | |
?> |
UPDATED;
`<?php
$address = "1600 Pennsylvania Ave NW Washington DC 20500";
$address = str_replace(" ", "+", $address);
$region = "USA";$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$region");
$json = json_decode($json);$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
echo $lat."
".$long;?> `
Hello, I want to get the postcode, I was able to get the postcode using the code below. The order of the postal code changes when the street address changes. Another information comes in place of the postal code.
$postalcode = $json->{'results'}[0]->{'address_components'}[6]->{'short_name'};
I couldn't solve the problem. {'address_components'}[6] Number is constantly changing 6, 5, 4
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
Now It require api key.
Is there any Way to get lat long from address for free?
Now It require api key.
Is there any Way to get lat long from address for free?
Use OSM.
check out open street map and/or leaflet it has everything you need