Here is the code snippet by which you can find the Latitude and Longitude using the Customer Address -
public function getLatLongArray($_Country, $_State)
{
$address = $_Country."+".$_State;
$_CountryName = Mage::app()->getLocale()->getCountryTranslation($_Country);
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$_CountryName";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo $lat = $response_a->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $response_a->results[0]->geometry->location->lng;
return array(
'latitude' => $lat,
'longitude' => $long,
);
}
Enjoy!! :-)
public function getLatLongArray($_Country, $_State)
{
$address = $_Country."+".$_State;
$_CountryName = Mage::app()->getLocale()->getCountryTranslation($_Country);
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$_CountryName";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo $lat = $response_a->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $response_a->results[0]->geometry->location->lng;
return array(
'latitude' => $lat,
'longitude' => $long,
);
}
Enjoy!! :-)