Skip to content

Commit

Permalink
Fix for #39
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Sep 9, 2024
1 parent 68a483f commit fe0ecad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Easy Address Field for Craft CMS

## 5.0.2 - 2024-09-09
### Fixed
- Better error catching on Nomanatim errors ([#39](https://github.com/studioespresso/craft-easyaddressfield/issues/39))

## 5.0.1 - 2024-08-07
### Fixed
- Fields now respect wether geocoding is enabled or not ([#38](https://github.com/studioespresso/craft-easyaddressfield/issues/38))
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "studioespresso/craft-easyaddressfield",
"description": "The only address field you need",
"type": "craft-plugin",
"version": "5.0.1",
"version": "5.0.2",
"keywords": [
"cms",
"craftcms",
Expand Down
4 changes: 2 additions & 2 deletions src/services/FieldService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function saveField(EasyAddressFieldField $field, ElementInterface $elemen
$record->city = $value->city;
$record->state = $value->state;
$record->country = $value->country;
$record->latitude = $value->latitude;
$record->longitude = $value->longitude;
$record->latitude = $value->latitude ?? null;
$record->longitude = $value->longitude ?? null;


$save = $record->save();
Expand Down
12 changes: 8 additions & 4 deletions src/services/GeoLocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ class GeoLocationService extends Component
*/
public function locate(EasyAddressFieldModel $model)
{
if (!$model->latitude && !$model->longitude and strlen($model->toString()) >= 2) {
$model = $this->geocodeOSM($model);
try {
if (!$model->latitude && !$model->longitude and strlen($model->toString()) >= 2) {
$model = $this->geocodeOSM($model);
}
return $model;
} catch (\Throwable $exception) {
\Craft::error($exception->getMessage());
return $model;
}

return $model;
}

private function geocodeOSM(EasyAddressFieldModel $model)
Expand Down

0 comments on commit fe0ecad

Please sign in to comment.