brookedot icon

Google Lan Lng from JSON

brookedot | PRO | 12/24/12 07:31:52 PM UTC | 0 ⭐ | 292 👁️ | Never ⏰ | []
PHP |

540 B

|

None

|

0 👍

/

0 👎

`<?php function toCoordinates($address)
{
    $bad = array(
        " " => "+",
        "," => "",
        "?" => "",
        "&" => "",
        "=" => ""
    );
    $address = str_replace(array_keys($bad), array_values($bad), $address);
    $data = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address={$address}&sensor=true",0,null,null),true);
 
    return array(
       "latitude" => $data[results][0][geometry][location][lat],
       "longitude" => $data[results][0][geometry][location][lng]
  );
} ?> `

Comments