Tagged: filter, Google Maps API
-
AuthorPosts
-
December 3, 2018 at 5:54 pm #1040415
the api_url function defined in clas-gmaps.php has a beautiful avf_google_maps_source filter that allows the google maps api url to be filtered. While this is great for updating the api version, any new arguments added to the $api_src array will be ignored.
For example:
add_filter( 'avf_google_maps_source', 'pi_google_maps_url', 10, 1 ); function pi_google_maps_url(array $api_src){ // update the current google maps api version $api_src['version'] = '3.35'; // add delicious new arguments $pi_args = array( 'libraries' => 'places', 'language' => 'de', 'region' => 'DE' ); $new_args = array_merge($api_src, $pi_args); return $new_args; }
Will update the version, however ignore the added arguments because a new $args array is being define and this is used to create the query args.
Any chance of either a) merging the $api_src into $args after the avf_google_maps_source filter is applied:
$api_src = apply_filters( 'avf_google_maps_source', $api_src ); // clone $api_src into $args $args = $api_src; // remove the version and source from the $args array unset($args['version'], $args['source']);
or better yet b) simply add a new filter for the $args array:
if( $api_key != '' ) { $args = apply_filters( 'avf_google_maps_args', $args ); $args['key'] = $api_key; }
December 10, 2018 at 3:14 am #1042868Hey Switzer,
Thank you for using Enfold.
That filter returns an array with the api url and the api version without the arguments, both are strings, so you can’t add arguments by returning or merging it in the array. You have to append the arguments as a query string in the api_url or “source” value.
add_filter( 'avf_google_maps_source', 'pi_google_maps_url', 10, 1 ); function pi_google_maps_url(array $api_src){ // update the current google maps api version $api_src['version'] = '3.35'; // add delicious new arguments $pi_args = array( 'libraries' => 'places', 'language' => 'de', 'region' => 'DE' ); $api_src['source'] = $api_src['source'] . '?' . http_build_query($pi_args); return $api_src; }
In the latest version, we’ll set the api version to release channels instead of the actual version number, so you don’t have to filter it.
// https://developers.google.com/maps/documentation/javascript/versions
Best regards,
IsmaelDecember 10, 2018 at 3:13 pm #1043108fine with the version… but still would be nice if you added a filter for the args array as mentioned above:
$args = apply_filters( 'avf_google_maps_args', $args );
Update: ah, I see… just filter the source and add my own arguments… ok, that also works.
Issue resolved.- This reply was modified 5 years, 11 months ago by SwitzerBaden.
December 10, 2018 at 9:33 pm #1043365Hi SwitzerBaden,
Glad you got it working for you! :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.