Command Line Application Using php

To find the longitude and latitude of city/state/address from user input string

fwrite(STDOUT, "Please enter your city state or address\n");
$address = fgets(STDIN);
//fwrite(STDOUT, "Welcome $name");
//$address = 'Kolhapur tarbai park'; // Google HQ
$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;

fwrite(STDOUT, $address.’
Lat: ‘.$lat.’
Long: ‘.$long);

 

Output

output

Advertisements