Skip to content

Commit

Permalink
re-added google geocoder; fixed links in shortcode helper page;
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin DeLong committed Dec 24, 2018
1 parent 4bf81a9 commit ca52b19
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 42 deletions.
60 changes: 24 additions & 36 deletions class.geocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,23 @@ private function get_url( $url ) {
* @return varies object from API or null (failed)
*/

private function google_geocode ( $address ) {
$geocode_url = 'https://maps.googleapis.com/maps/api/geocode/json?address=';
$geocode_url .= $address;
$json = $this->get_url($geocode_url);
private function google_geocode ( $address ) {
// Leaflet_Map_Plugin_Settings
$settings = Leaflet_Map_Plugin_Settings::init();
$key = $settings->get('google_appkey');

$geocode_url = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=%s';
$geocode_url = sprintf($geocode_url, $address, $key);

$json = $this->get_url($geocode_url);
$json = json_decode($json);

if ($json) {
$json = json_decode($json);
/* found location */
if ($json->{'status'} == 'OK') {

$location = $json->{'results'}[0]->{'geometry'}->{'location'};
/* found location */
if ($json->status == 'OK') {

$location = $json->results[0]->geometry->location;

return (Object) $location;
}
return (Object) $location;
}

throw new Exception('No Address Found');
Expand All @@ -152,17 +155,10 @@ private function osm_geocode ( $address ) {
$json = $this->get_url($geocode_url);
$json = json_decode($json);

if (is_array($json) &&
is_object($json[0]) &&
$json[0]->lat) {
// found location
return (Object) array(
'lat' => $json[0]->lat,
'lng' => $json[0]->lon,
);
}

throw new Exception('No Address Found');
return (Object) array(
'lat' => $json[0]->lat,
'lng' => $json[0]->lon,
);
}

/**
Expand All @@ -179,18 +175,10 @@ private function dawa_geocode ( $address ) {
$json = $this->get_url($geocode_url);
$json = json_decode($json);

if (is_array($json) &&
is_object($json[0]) &&
$json[0]->status == 1) {
/* found location */
$location = (Object) array(
'lat' => $json[0]->adgangsadresse->adgangspunkt->koordinater[1],
'lng' => $json[0]->adgangsadresse->adgangspunkt->koordinater[0]
);

return $location;
}

throw new Exception('No Address Found');
/* found location */
return (Object) array(
'lat' => $json[0]->adgangsadresse->adgangspunkt->koordinater[1],
'lng' => $json[0]->adgangsadresse->adgangspunkt->koordinater[0]
);
}
}
2 changes: 1 addition & 1 deletion class.plugin-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function __construct($details = array())
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_FORCE_ARRAY
),
'helptext' => FILTER_SANITIZE_STRING
'helptext' => null
);

// get matching keys only
Expand Down
24 changes: 21 additions & 3 deletions class.plugin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private function __construct()
'helptext' => __('Choose a tiling service or provide your own.', 'leaflet-map')
),
'mapquest_appkey' => array(
'display_name'=>__('MapQuest App Key', 'leaflet-map'),
'display_name'=>__('MapQuest App Key (optional)', 'leaflet-map'),
'default' => __('Supply an app key if you choose MapQuest', 'leaflet-map'),
'type' => 'text',
'noreset' => true,
Expand Down Expand Up @@ -267,7 +267,20 @@ private function __construct()
'dawa' => __('Denmark Addresses', 'leaflet-map')
),
'helptext' => __('Select the Geocoding provider to use to retrieve addresses defined in shortcode.', 'leaflet-map')
)
),
'google_appkey' => array(
'display_name'=>__('Google API Key (optional)', 'leaflet-map'),
'default' => __('Supply a Google API Key', 'leaflet-map'),
'type' => 'text',
'noreset' => true,
'helptext' => sprintf(
'%1$s: <a href="https://cloud.google.com/maps-platform/?apis=places" target="_blank">%2$s</a>. %3$s %4$s',
__('The Google Geocoder requires an API key with the Places product enabled', 'leaflet-map'),
__('here', 'leaflet-map'),
__('You must create a project and set up a billing account, then you will be given an API key.', 'leaflet-map'),
__('You are unlikely to ever be charged for geocoding.', 'leaflet-map')
),
),
);

foreach ($this->options as $name => $details) {
Expand Down Expand Up @@ -324,7 +337,12 @@ public function delete($key)
public function reset()
{
foreach ($this->options as $name => $option) {
$this->delete($name);
if (
!array_key_exists('noreset', $options) ||
$options['noreset'] != true
) {
$this->delete($name);
}
}
return $this;
}
Expand Down
4 changes: 3 additions & 1 deletion templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
$form[$name] = isset($_POST[ $name ]) ? 1 : 0;
}

$settings->set($name, stripslashes( $form[$name]));
$value = trim( stripslashes( $form[$name]) );

$settings->set($name, $value);
}
?>
<div class="notice notice-success is-dismissible">
Expand Down
2 changes: 1 addition & 1 deletion templates/shortcode-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
),
__("SVG Marker Icon", 'leaflet-map') => array(
'[leaflet-map address="twilight lane, nova scotia" scrollwheel]',
'[leaflet-marker svg background="#654" iconClass="dashicons dashicons-star-filled" color="gold"]My Favorite Place in the World[/leaflet-marker]'
'[leaflet-marker svg background="#777" iconClass="dashicons dashicons-star-filled" color="gold"]My Favorite Place in the World[/leaflet-marker]'
),
__("Zoom Buttons", 'leaflet-map') => array(
'[leaflet-map zoom=9 lat=48.855 lng=2.35 zoomcontrol]',
Expand Down

0 comments on commit ca52b19

Please sign in to comment.