From fe1a5a8c250292ced21545c10f76501bbdaad100 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Wed, 30 Sep 2020 14:05:19 +0000 Subject: [PATCH] fix geocoder and better error handling --- p3k/Geocoder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p3k/Geocoder.php b/p3k/Geocoder.php index 0c75d58..4d8736b 100644 --- a/p3k/Geocoder.php +++ b/p3k/Geocoder.php @@ -41,7 +41,7 @@ class Geocoder { public static function geocode($input) { $response = self::_geocode($input); - if(!$response || count($response->locations) == 0) + if(!$response || !property_exists($response, 'locations') || count($response->locations) == 0) return false; $location = $response->locations[0]; @@ -106,7 +106,7 @@ class Geocoder { 'outFields' => 'City,Region,Country,Postal', ]; - curl_setopt($ch, CURLOPT_URL, 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?' . http_build_query($params)); + curl_setopt($ch, CURLOPT_URL, 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?' . http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // curl_setopt($ch, CURLOPT_USERAGENT, ''); curl_setopt($ch, CURLOPT_TIMEOUT, 5);