3v4l.org

run code in 300+ PHP versions simultaneously
<?php // some address values $client_address = '11010 Langton Arms Court'; $client_city = 'Oakton'; $client_state = 'VA'; $client_zip = '22124'; // building the JSON URL string for Google API call $g_address = str_replace(' ', '+', trim($client_address)).","; $g_city = '+'.str_replace(' ', '+', trim($client_city)).","; $g_state = '+'.str_replace(' ', '+', trim($client_state)); $g_zip = isset($client_zip)? '+'.str_replace(' ', '', trim($client_zip)) : ''; $g_addr_str = $g_address.$g_city.$g_state.$g_zip; $url = "http://maps.google.com/maps/api/geocode/json? address=$g_addr_str"; // Parsing the JSON response from the Google Geocode API to get exact map coordinates: // latitude , longitude (see the Google doc. for the complete data return here: // https://developers.google.com/maps/documentation/geocoding/.) $jsonData = file_get_contents($url); $data = json_decode($jsonData); $xlat = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'}; $xlong = $data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'}; echo $xlat.",".$xlong;

preferences:
56.32 ms | 402 KiB | 5 Q