Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cater for field type google_map #10

Open
bobbingwide opened this issue Jul 7, 2023 · 2 comments
Open

Cater for field type google_map #10

bobbingwide opened this issue Jul 7, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Jul 7, 2023

According to the documentation at https://www.advancedcustomfields.com/resources/google-map/
the Google Map field provides an interactive map interface for selecting a location.

This field type uses the Google Maps JS API to provide autocomplete searching, reverse geocoding lookup and an interactive marker.

Requirement

  • To be able to render the Google Map on the front end.

Proposed solution

  • The Google Maps API requires an API key.

  • ACF finds this using a filter function ( acf/fields/google_map/api ), passing in the values obtained from acf_get_setting(), for both google_api_key and google_api_client.

  • The field type should only be supported when an API key is available.
    One way of achieving this is to define a Google Maps Field group, which contains the text field for the API key, and is displayed on the ACF Options page(s).

  • This might require the plugin to call acf_add_options_page(), to ensure an Options page is available, and to define the Google Maps field group.

  • Perhaps this can be achieved by the rendering logic when a field of this type is first encountered?!

  • For helper code see https://www.advancedcustomfields.com/resources/google-map/#google-maps-helper-code

@bobbingwide bobbingwide added the enhancement New feature or request label Jul 7, 2023
@bobbingwide bobbingwide self-assigned this Jul 7, 2023
@bobbingwide
Copy link
Owner Author

$field array could contain

Array

    [address] => (string) "Redhill Road, Rowland's Castle PO9 6DE, UK"
    [lat] => (double) 50.8869073
    [lng] => (double) -0.9662887
    [zoom] => (integer) 13
    [place_id] => (string) "ChIJQfF3bKlFdEgRpSjEMleMGRU"
    [name] => (string) "PO9 6DE"
    [street_name] => (string) "Redhill Road"
    [street_name_short] => (string) "Redhill Rd"
    [city] => (string) "Rowland's Castle"
    [state] => (string) "England"
    [post_code] => (string) "PO9 6DE"
    [country] => (string) "United Kingdom"
    [country_short] => (string) "GB"

$field_info array could contain these fields used to display the Google Maps map.

 [center_lat] => (string) ""
 [center_lng] => (string) ""
 [zoom] => (string) ""
 [height] => (string) ""

@bobbingwide
Copy link
Owner Author

bobbingwide commented Jul 10, 2023

We need to cater for nulls.

When the Google Maps address hadn't been set the first version of the code displayed a series of PHP Warnings.
The logic should cater for $field values not being set.

We need to consider what to display in the block editor.

When the API key is set then the required JavaScript is enqueued. But the Google Maps don't appear in the block, even though they do appear in the Meta boxes.
What can be done about this?
Can the potential presence of a Google Maps field be used to enqueue the JavaScript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant