user3029877 user3029877 -3 years ago 92
PHP Question

geocoding address from form

Im using this form to geocode addresses on user input. How do I get only the lat and lon not the entire array printed to page. Here is page 1.php :

<form action="2.php" method="get">
<input type="text" name="adress" /><br />
<input type="submit" />
</form>


page 2.php :

First Name: <?php echo $_GET["adress"]; ?><br />
<?php
$address= $_GET["adress"];
$result=file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" . urlencode($address) );
$geocodedinfo=json_decode($result);

print_r($geocodedinfo);
?>

Answer Source

The easiest way is to print out the array that you want. I would like to see the results of your full array though. Lets say that you get this array lat[], long[], etc[], etc[]..

print_r($geocodedinfo['lat']. $geocodedinfo['long']);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download