Skip to content

Commit e01c2d8

Browse files
committed
removed optional dependency on an internal geocoding library that isn't open source
1 parent d9981f0 commit e01c2d8

File tree

1 file changed

+15
-21
lines changed
  • app/code/community/Demac/MultiLocationInventory/Helper

1 file changed

+15
-21
lines changed

app/code/community/Demac/MultiLocationInventory/Helper/Data.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,23 @@ public function getRegions($countryCode)
6262
public function getLatLong($postalCode, $country)
6363
{
6464
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&region=$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);
6776

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&region=$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;
8580

86-
return array($lat, $long);
87-
}
81+
return array($lat, $long);
8882
}
8983

9084
/**

0 commit comments

Comments
 (0)