From e054386662fd268382c00724c8ba3c43d5582289 Mon Sep 17 00:00:00 2001 From: Mohammed Rhamnia Date: Mon, 27 Jun 2016 18:18:17 +0100 Subject: [PATCH 1/2] add possiblity to define the api key on geocode class --- Service/Geocoder.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Service/Geocoder.php b/Service/Geocoder.php index 3004b78..e434d8f 100644 --- a/Service/Geocoder.php +++ b/Service/Geocoder.php @@ -30,12 +30,13 @@ class Geocoder { * * @link http://code.google.com/apis/maps/documentation/geocoding/ * - * @param string $location - * @param boolean $simple If true, only the lat/lng will be returned + * @param string $location Location to geocode + * @param string $key API key + * * @return GeocodeResult|GeocodeError */ - public static function geocode( $location ) { - $response = self::scrapeAPI( $location ); + public static function geocode( $location, $key = null ) { + $response = self::scrapeAPI( $location, $key); if ( $response->status != 'OK' ) { $error = new GeocodeError( $response->status, $location ); return $error; @@ -47,12 +48,17 @@ public static function geocode( $location ) { * Scrape the API * * @param string $location Location to geocode + * @param string $key API key + * * @return GeocodeError|LatLng Returns a GeocodeError on error, LatLng on success. */ - private static function scrapeAPI( $location ) { + private static function scrapeAPI( $location, $key ) { $url = sprintf( "http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false", urlencode( $location ) ); + if (isset($url)) { + $url .= "&key=" . $key; + } $response = json_decode( Scraper::scrape( $url ) ); return $response; } -} \ No newline at end of file +} From a201638866a675963c63cc7ec1caa8dd393eecc4 Mon Sep 17 00:00:00 2001 From: Mohammed Rhamnia Date: Mon, 27 Jun 2016 19:10:07 +0100 Subject: [PATCH 2/2] force https --- Service/Geocoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/Geocoder.php b/Service/Geocoder.php index e434d8f..5552438 100644 --- a/Service/Geocoder.php +++ b/Service/Geocoder.php @@ -53,7 +53,7 @@ public static function geocode( $location, $key = null ) { * @return GeocodeError|LatLng Returns a GeocodeError on error, LatLng on success. */ private static function scrapeAPI( $location, $key ) { - $url = sprintf( "http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false", urlencode( $location ) ); + $url = sprintf( "https://maps.google.com/maps/api/geocode/json?address=%s&sensor=false", urlencode( $location ) ); if (isset($url)) { $url .= "&key=" . $key; }