Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/Geocoder/Provider/ArcGISOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,28 @@ final class ArcGISOnline extends AbstractHttpProvider implements Provider
/**
* @var string
*/
const ENDPOINT_URL = '%s://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=%s';
const ENDPOINT_URL = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=%s';

/**
* @var string
*/
const REVERSE_ENDPOINT_URL = '%s://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=%F,%F';
const REVERSE_ENDPOINT_URL = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=%F,%F';

/**
* @var string
*/
private $sourceCountry;

/**
* @var string
*/
private $protocol;

/**
* @param HttpClient $client An HTTP adapter
* @param string $sourceCountry Country biasing (optional)
* @param bool $useSsl Whether to use an SSL connection (optional)
*/
public function __construct(HttpClient $client, $sourceCountry = null, $useSsl = false)
public function __construct(HttpClient $client, $sourceCountry = null)
{
parent::__construct($client);

$this->sourceCountry = $sourceCountry;
$this->protocol = $useSsl ? 'https' : 'http';
}

/**
Expand All @@ -66,7 +60,7 @@ public function geocode($address)
throw new NoResult('Invalid address.');
}

$query = sprintf(self::ENDPOINT_URL, $this->protocol, urlencode($address));
$query = sprintf(self::ENDPOINT_URL, urlencode($address));
$json = $this->executeQuery($query);

// no result
Expand Down Expand Up @@ -112,7 +106,7 @@ public function geocode($address)
*/
public function reverse($latitude, $longitude)
{
$query = sprintf(self::REVERSE_ENDPOINT_URL, $this->protocol, $longitude, $latitude);
$query = sprintf(self::REVERSE_ENDPOINT_URL, $longitude, $latitude);
$json = $this->executeQuery($query);

if (property_exists($json, 'error')) {
Expand Down
4 changes: 2 additions & 2 deletions src/Geocoder/Provider/BingMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ final class BingMaps extends AbstractHttpProvider implements LocaleAwareProvider
/**
* @var string
*/
const GEOCODE_ENDPOINT_URL = 'http://dev.virtualearth.net/REST/v1/Locations/?maxResults=%d&q=%s&key=%s&incl=ciso2';
const GEOCODE_ENDPOINT_URL = 'https://dev.virtualearth.net/REST/v1/Locations/?maxResults=%d&q=%s&key=%s&incl=ciso2';

/**
* @var string
*/
const REVERSE_ENDPOINT_URL = 'http://dev.virtualearth.net/REST/v1/Locations/%F,%F?key=%s&incl=ciso2';
const REVERSE_ENDPOINT_URL = 'https://dev.virtualearth.net/REST/v1/Locations/%F,%F?key=%s&incl=ciso2';

/**
* @var string
Expand Down
34 changes: 5 additions & 29 deletions src/Geocoder/Provider/GoogleMaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,11 @@
*/
final class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvider
{
/**
* @var string
*/
const GEOCODE_ENDPOINT_URL = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s';

/**
* @var string
*/
const GEOCODE_ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s';

/**
* @var string
*/
const REVERSE_ENDPOINT_URL = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=%F,%F';

/**
* @var string
*/
Expand All @@ -49,11 +39,6 @@ final class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvid
*/
private $region;

/**
* @var bool
*/
private $useSsl;

/**
* @var string
*/
Expand All @@ -78,13 +63,12 @@ final class GoogleMaps extends AbstractHttpProvider implements LocaleAwareProvid
* @param string $privateKey Your Private Key (optional)
* @param string $locale A locale (optional)
* @param string $region Region biasing (optional)
* @param bool $useSsl Whether to use an SSL connection (optional)
* @param string $apiKey Google Geocoding API key (optional)
* @return GoogleMaps
*/
public static function business(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $useSsl = false, $apiKey = null)
public static function business(HttpClient $client, $clientId, $privateKey = null, $locale = null, $region = null, $apiKey = null)
{
$provider = new self($client, $locale, $region, $useSsl, $apiKey);
$provider = new self($client, $locale, $region, $apiKey);
$provider->clientId = $clientId;
$provider->privateKey = $privateKey;

Expand All @@ -95,16 +79,14 @@ public static function business(HttpClient $client, $clientId, $privateKey = nul
* @param HttpClient $client An HTTP adapter
* @param string $locale A locale (optional)
* @param string $region Region biasing (optional)
* @param bool $useSsl Whether to use an SSL connection (optional)
* @param string $apiKey Google Geocoding API key (optional)
*/
public function __construct(HttpClient $client, $locale = null, $region = null, $useSsl = false, $apiKey = null)
public function __construct(HttpClient $client, $locale = null, $region = null, $apiKey = null)
{
parent::__construct($client);

$this->locale = $locale;
$this->region = $region;
$this->useSsl = $useSsl;
$this->apiKey = $apiKey;
}

Expand All @@ -119,10 +101,7 @@ public function geocode($address)
throw new UnsupportedOperation('The GoogleMaps provider does not support IP addresses, only street addresses.');
}

$query = sprintf(
$this->useSsl ? self::GEOCODE_ENDPOINT_URL_SSL : self::GEOCODE_ENDPOINT_URL,
rawurlencode($address)
);
$query = sprintf(self::GEOCODE_ENDPOINT_URL_SSL, rawurlencode($address));

return $this->executeQuery($query);
}
Expand All @@ -132,10 +111,7 @@ public function geocode($address)
*/
public function reverse($latitude, $longitude)
{
$query = sprintf(
$this->useSsl ? self::REVERSE_ENDPOINT_URL_SSL : self::REVERSE_ENDPOINT_URL,
$latitude, $longitude
);
$query = sprintf(self::REVERSE_ENDPOINT_URL_SSL, $latitude, $longitude);

return $this->executeQuery($query);
}
Expand Down
20 changes: 7 additions & 13 deletions src/Geocoder/Provider/Mapzen.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace Geocoder\Provider;

use Geocoder\Collection;
use Geocoder\Exception\InvalidCredentials;
use Geocoder\Exception\QuotaExceeded;
use Geocoder\Exception\NoResult;
Expand All @@ -23,17 +24,12 @@ final class Mapzen extends AbstractHttpProvider
/**
* @var string
*/
const GEOCODE_ENDPOINT_URL = '%s://search.mapzen.com/v1/search?text=%s&key=%s&size=%d';
const GEOCODE_ENDPOINT_URL = 'https://search.mapzen.com/v1/search?text=%s&key=%s&size=%d';

/**
* @var string
*/
const REVERSE_ENDPOINT_URL = '%s://search.mapzen.com/v1/reverse?point.lat=%f&point.lon=%f&key=%s&size=%d';

/**
* @var string
*/
private $scheme;
const REVERSE_ENDPOINT_URL = 'https://search.mapzen.com/v1/reverse?point.lat=%f&point.lon=%f&key=%s&size=%d';

/**
* @var string
Expand All @@ -43,14 +39,12 @@ final class Mapzen extends AbstractHttpProvider
/**
* @param HttpClient $client An HTTP adapter.
* @param string $apiKey An API key.
* @param bool $useSsl Whether to use an SSL connection (optional).
*/
public function __construct(HttpClient $client, $apiKey, $useSSL = true)
public function __construct(HttpClient $client, $apiKey)
{
parent::__construct($client);

$this->apiKey = $apiKey;
$this->scheme = $useSSL ? 'https' : 'http';
}

/**
Expand All @@ -67,7 +61,7 @@ public function geocode($address)
throw new UnsupportedOperation('The Mapzen provider does not support IP addresses, only street addresses.');
}

$query = sprintf(self::GEOCODE_ENDPOINT_URL, $this->scheme, urlencode($address), $this->apiKey, $this->getLimit());
$query = sprintf(self::GEOCODE_ENDPOINT_URL, urlencode($address), $this->apiKey, $this->getLimit());

return $this->executeQuery($query);
}
Expand All @@ -81,7 +75,7 @@ public function reverse($latitude, $longitude)
throw new InvalidCredentials('No API Key provided.');
}

$query = sprintf(self::REVERSE_ENDPOINT_URL, $this->scheme, $latitude, $longitude, $this->apiKey, $this->getLimit());
$query = sprintf(self::REVERSE_ENDPOINT_URL, $latitude, $longitude, $this->apiKey, $this->getLimit());

return $this->executeQuery($query);
}
Expand All @@ -96,7 +90,7 @@ public function getName()

/**
* @param $query
* @return \Geocoder\Model\AddressCollection
* @return Collection
*/
private function executeQuery($query)
{
Expand Down
22 changes: 5 additions & 17 deletions src/Geocoder/Provider/MaxMind.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Geocoder\Provider;

use Geocoder\Collection;
use Geocoder\Exception\InvalidCredentials;
use Geocoder\Exception\NoResult;
use Geocoder\Exception\UnsupportedOperation;
Expand All @@ -30,11 +31,6 @@ final class MaxMind extends AbstractHttpProvider implements Provider
*/
const OMNI_SERVICE = 'e';

/**
* @var string
*/
const GEOCODE_ENDPOINT_URL = 'http://geoip.maxmind.com/%s?l=%s&i=%s';

/**
* @var string
*/
Expand All @@ -50,24 +46,17 @@ final class MaxMind extends AbstractHttpProvider implements Provider
*/
private $service = null;

/**
* @var bool
*/
private $useSsl = false;

/**
* @param HttpClient $client An HTTP adapter.
* @param string $apiKey An API key.
* @param string $service The specific Maxmind service to use (optional).
* @param bool $useSsl Whether to use an SSL connection (optional).
*/
public function __construct(HttpClient $client, $apiKey, $service = self::CITY_EXTENDED_SERVICE, $useSsl = false)
public function __construct(HttpClient $client, $apiKey, $service = self::CITY_EXTENDED_SERVICE)
{
parent::__construct($client);

$this->apiKey = $apiKey;
$this->service = $service;
$this->useSsl = $useSsl;
}

/**
Expand All @@ -87,10 +76,7 @@ public function geocode($address)
return $this->returnResults([ $this->getLocalhostDefaults() ]);
}

$query = sprintf(
$this->useSsl ? self::GEOCODE_ENDPOINT_URL_SSL : self::GEOCODE_ENDPOINT_URL,
$this->service, $this->apiKey, $address
);
$query = sprintf(self::GEOCODE_ENDPOINT_URL_SSL, $this->service, $this->apiKey, $address);

return $this->executeQuery($query);
}
Expand All @@ -113,6 +99,8 @@ public function getName()

/**
* @param string $query
*
* @return Collection
*/
private function executeQuery($query)
{
Expand Down
12 changes: 3 additions & 9 deletions src/Geocoder/Provider/OpenCage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ final class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider
/**
* @var string
*/
const GEOCODE_ENDPOINT_URL = '%s://api.opencagedata.com/geocode/v1/json?key=%s&query=%s&limit=%d&pretty=1';
const GEOCODE_ENDPOINT_URL = 'https://api.opencagedata.com/geocode/v1/json?key=%s&query=%s&limit=%d&pretty=1';

use LocaleTrait;

/**
* @var string
*/
private $scheme;

/**
* @var string
*/
Expand All @@ -44,12 +39,11 @@ final class OpenCage extends AbstractHttpProvider implements LocaleAwareProvider
* @param bool $useSsl Whether to use an SSL connection (optional).
* @param string|null $locale A locale (optional).
*/
public function __construct(HttpClient $client, $apiKey, $useSsl = false, $locale = null)
public function __construct(HttpClient $client, $apiKey, $locale = null)
{
parent::__construct($client);

$this->apiKey = $apiKey;
$this->scheme = $useSsl ? 'https' : 'http';
$this->locale = $locale;
}

Expand All @@ -67,7 +61,7 @@ public function geocode($address)
throw new UnsupportedOperation('The OpenCage provider does not support IP addresses, only street addresses.');
}

$query = sprintf(self::GEOCODE_ENDPOINT_URL, $this->scheme, $this->apiKey, urlencode($address), $this->getLimit());
$query = sprintf(self::GEOCODE_ENDPOINT_URL, $this->apiKey, urlencode($address), $this->getLimit());

return $this->executeQuery($query);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
s:111:"{
"error_message" : "The provided API key is invalid.",
"results" : [],
"status" : "REQUEST_DENIED"
}
";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s:4697:"{"spatialReference":{"wkid":4326,"latestWkid":4326},"locations":[{"name":"Hannover, Niedersachsen, Deutschland","extent":{"xmin":9.6292190000000009,"ymin":52.266517,"xmax":9.8372189999999993,"ymax":52.474516999999999},"feature":{"geometry":{"x":9.7332192330004546,"y":52.370516553000471},"attributes":{"Loc_name":"Gaz.WorldGazetteer.POI1","Score":100,"Match_addr":"Hannover, Niedersachsen, Deutschland","Addr_type":"POI","Type":"State Capital","PlaceName":"Hannover","Place_addr":"","Phone":"","URL":"","Rank":"3","AddBldg":"","AddNum":"","AddNumFrom":"","AddNumTo":"","Side":"","StPreDir":"","StPreType":"","StName":"","StType":"","StDir":"","StAddr":"","Nbrhd":"","City":"","Subregion":"","Region":"Niedersachsen","Postal":"","PostalExt":"","Country":"DEU","LangCode":"","Distance":0,"X":9.7332190000000001,"Y":52.370517,"DisplayX":9.7332190000000001,"DisplayY":52.370517,"Xmin":9.6292190000000009,"Xmax":9.8372189999999993,"Ymin":52.266517,"Ymax":52.474516999999999}}},{"name":"Hannover, North Dakota, United States","extent":{"xmin":-101.446538,"ymin":47.091388000000002,"xmax":-101.406538,"ymax":47.131388000000001},"feature":{"geometry":{"x":-101.42653668599968,"y":47.111387737000484},"attributes":{"Loc_name":"Gaz.WorldGazetteer.POI1","Score":100,"Match_addr":"Hannover, North Dakota, United States","Addr_type":"POI","Type":"City","PlaceName":"Hannover","Place_addr":"","Phone":"","URL":"","Rank":"12.5","AddBldg":"","AddNum":"","AddNumFrom":"","AddNumTo":"","Side":"","StPreDir":"","StPreType":"","StName":"","StType":"","StDir":"","StAddr":"","Nbrhd":"","City":"","Subregion":"Oliver","Region":"North Dakota","Postal":"","PostalExt":"","Country":"USA","LangCode":"","Distance":0,"X":-101.42653799999999,"Y":47.111387999999998,"DisplayX":-101.42653799999999,"DisplayY":47.111387999999998,"Xmin":-101.446538,"Xmax":-101.406538,"Ymin":47.091388000000002,"Ymax":47.131388000000001}}},{"name":"Hannover, Maryland, United States","extent":{"xmin":-77.460260000000005,"ymin":39.371769,"xmax":-77.420259999999999,"ymax":39.411769},"feature":{"geometry":{"x":-77.44025867799968,"y":39.391769260000444},"attributes":{"Loc_name":"Gaz.WorldGazetteer.POI1","Score":100,"Match_addr":"Hannover, Maryland, United States","Addr_type":"POI","Type":"City","PlaceName":"Hannover","Place_addr":"","Phone":"","URL":"","Rank":"12.5","AddBldg":"","AddNum":"","AddNumFrom":"","AddNumTo":"","Side":"","StPreDir":"","StPreType":"","StName":"","StType":"","StDir":"","StAddr":"","Nbrhd":"","City":"","Subregion":"Frederick","Region":"Maryland","Postal":"","PostalExt":"","Country":"USA","LangCode":"","Distance":0,"X":-77.440259999999995,"Y":39.391768999999996,"DisplayX":-77.440259999999995,"DisplayY":39.391768999999996,"Xmin":-77.460260000000005,"Xmax":-77.420259999999999,"Ymin":39.371769,"Ymax":39.411769}}},{"name":"Hannöver, Niedersachsen, Deutschland","extent":{"xmin":8.5029389999999996,"ymin":53.170198999999997,"xmax":8.5109390000000005,"ymax":53.178198999999999},"feature":{"geometry":{"x":8.5069385510004167,"y":53.174199236000504},"attributes":{"Loc_name":"Gaz.WorldGazetteer.POI1","Score":100,"Match_addr":"Hannöver, Niedersachsen, Deutschland","Addr_type":"POI","Type":"City","PlaceName":"Hannöver","Place_addr":"","Phone":"","URL":"","Rank":"12.5","AddBldg":"","AddNum":"","AddNumFrom":"","AddNumTo":"","Side":"","StPreDir":"","StPreType":"","StName":"","StType":"","StDir":"","StAddr":"","Nbrhd":"","City":"","Subregion":"","Region":"Niedersachsen","Postal":"","PostalExt":"","Country":"DEU","LangCode":"","Distance":0,"X":8.5069389999999991,"Y":53.174199000000002,"DisplayX":8.5069389999999991,"DisplayY":53.174199000000002,"Xmin":8.5029389999999996,"Xmax":8.5109390000000005,"Ymin":53.170198999999997,"Ymax":53.178198999999999}}},{"name":"Hannover","extent":{"xmin":-48.854387000000003,"ymin":-26.286808000000001,"xmax":-48.844386999999998,"ymax":-26.276807999999999},"feature":{"geometry":{"x":-48.849386270999616,"y":-26.281806506999601},"attributes":{"Loc_name":"Gaz.WorldGazetteer.POI2","Score":100,"Match_addr":"Hannover","Addr_type":"POI","Type":"Hotel","PlaceName":"Hannover","Place_addr":"Rua Doutor João Colin, Joinville, Sul","Phone":"","URL":"","Rank":"19","AddBldg":"","AddNum":"","AddNumFrom":"","AddNumTo":"","Side":"","StPreDir":"","StPreType":"","StName":"","StType":"","StDir":"","StAddr":"Rua Doutor João Colin","Nbrhd":"América","City":"Joinville","Subregion":"Santa Catarina","Region":"Sul","Postal":"","PostalExt":"","Country":"BRA","LangCode":"POR","Distance":0,"X":-48.849387,"Y":-26.281808000000002,"DisplayX":-48.849387,"DisplayY":-26.281808000000002,"Xmin":-48.854387000000003,"Xmax":-48.844386999999998,"Ymin":-26.286808000000001,"Ymax":-26.276807999999999}}}]}";
Loading