问题
I have a registration form that I would like to fill with data when a user arrives on this section of the form. The first part of the form asks for the postcode/zip code. On the form load I would like to be able to display a list of house numbers with the street name.
This is what I have to return the data
<?php
$postcode = 'DH90ER';
$geourl = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$postcode&sensor=true");
$array = json_decode($geourl,TRUE);
print header("Content-type: text/plain");
print_r($array);
?>
This works it reruns an array of information that i need except the street name or numbers. For example if I echo
echo $array['results'][0]['address_components'][1]['long_name'];
This would echo the Town name. Its messy I know but it works really well. Is there a way I can get a the street name as postal codes are unique to street names and the number of possible houses?
I've been stuck for a while on this, I will use javascript if it is possible with javascript.
UPDATE to return single house number and street name
$geourl = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$postcode&sensor=true");
$array = json_decode($geourl,TRUE);
print header("Content-type: text/plain");
$lat = $array['results'][0]['geometry']['location']['lat'];
$lng = $array['results'][0]['geometry']['location']['lng'];
$add = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng");
$add = json_decode($add);
print_r($add);
来源:https://stackoverflow.com/questions/27228768/use-google-geocode-to-return-street-name-and-list-of-house-numbers-using-php