Jun 25, 2013

Get Latitude & Longitude from address

function getLatLong($address){
    $prep_addr = str_replace(' ','+',$address);

    $geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prep_addr.'&sensor=false');

    $output= json_decode($geocode);

    $lat = $output->results[0]->geometry->location->lat;
    $long = $output->results[0]->geometry->location->lng;

    return array("latitude" => $lat, "longitude" => $long);
}

No comments:

Post a Comment

Want to tell something about this post. Please feel free to write...