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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s