brookedot

Google Lan Lng from JSON

Dec 24th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. `<?php function toCoordinates($address)
  2. {
  3.     $bad = array(
  4.         " " => "+",
  5.         "," => "",
  6.         "?" => "",
  7.         "&" => "",
  8.         "=" => ""
  9.     );
  10.     $address = str_replace(array_keys($bad), array_values($bad), $address);
  11.     $data = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address={$address}&sensor=true",0,null,null),true);
  12.  
  13.     return array(
  14.        "latitude" => $data[results][0][geometry][location][lat],
  15.        "longitude" => $data[results][0][geometry][location][lng]
  16.   );
  17. } ?> `
Add Comment
Please, Sign In to add comment