fork(4) download
  1. <?php
  2. function getGeocodeAddress($lat, $long)
  3. {
  4. $url = "https://maps-api-ssl.google.com/maps/api/geocode/json?latlng=" . $lat . "," . $long . "&sensor=true";
  5.  
  6. $data = @file_get_contents($url);
  7. $jsondata = json_decode($data, true);
  8. if (is_array($jsondata) && $jsondata['status'] == "OK") {
  9. $addressComponents = $jsondata['results'];
  10. for ($i = 0; $i < count($addressComponents); $i++) {
  11. for ($j = 0; $j < count($addressComponents[$i]['address_components']); $j++) {
  12. $typeName = $addressComponents[$i]['address_components'][$j]['types'][0];
  13. if ('locality' == $typeName) {
  14. return strtolower($addressComponents[$i]['address_components'][$j]['long_name']);
  15. }
  16. }
  17. }
  18. }
  19. return null;
  20. }
  21. echo getGeocodeAddress('-23.6453505', '-46.7914009');
Success #stdin #stdout 0.03s 52560KB
stdin
Standard input is empty
stdout
Standard output is empty