@@ -62,29 +62,23 @@ public function getRegions($countryCode)
62
62
public function getLatLong ($ postalCode , $ country )
63
63
{
64
64
sleep (1 );
65
- if ($ this ->geocodingAvailable ()) {
66
- $ coordinates = Mage::getModel ('geocoding/geocode ' )->loadByPostalCode ($ postalCode , $ country );
65
+ $ postalCode = urlencode ($ postalCode );
66
+ $ country = urlencode ($ country );
67
+ $ url = "http://maps.google.com/maps/api/geocode/json?address= $ postalCode&sensor=false®ion= $ country " ;
68
+ $ ch = curl_init ();
69
+ curl_setopt ($ ch , CURLOPT_URL , $ url );
70
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
71
+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , 0 );
72
+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 0 );
73
+ $ response = curl_exec ($ ch );
74
+ curl_close ($ ch );
75
+ $ response_a = json_decode ($ response );
67
76
68
- return array ($ coordinates ['latitude ' ], $ coordinates ['longitude ' ]);
69
- } else {
70
- $ postalCode = urlencode ($ postalCode );
71
- $ country = urlencode ($ country );
72
- $ url = "http://maps.google.com/maps/api/geocode/json?address= $ postalCode&sensor=false®ion= $ country " ;
73
- $ ch = curl_init ();
74
- curl_setopt ($ ch , CURLOPT_URL , $ url );
75
- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
76
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , 0 );
77
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 0 );
78
- $ response = curl_exec ($ ch );
79
- curl_close ($ ch );
80
- $ response_a = json_decode ($ response );
81
-
82
- //@TODO handle invalid api responses that don't contain this element.
83
- $ lat = $ response_a ->results [0 ]->geometry ->location ->lat ;
84
- $ long = $ response_a ->results [0 ]->geometry ->location ->lng ;
77
+ //@TODO handle invalid api responses that don't contain this element.
78
+ $ lat = $ response_a ->results [0 ]->geometry ->location ->lat ;
79
+ $ long = $ response_a ->results [0 ]->geometry ->location ->lng ;
85
80
86
- return array ($ lat , $ long );
87
- }
81
+ return array ($ lat , $ long );
88
82
}
89
83
90
84
/**
0 commit comments