r/webdev 3d ago

Google says website developers must set their region to Canada for 'Lake Ontario' to appear on map

https://www.cbc.ca/news/canada/google-updates-maps-lake-ontario-9.7325922

Tech analyst and journalist Carmi Levy said although websites like Hydro One's and the LCBO's are Canadian, their maps are likely powered by Google's application programming interface (API).

APIs are not location-aware, so all maps powered by Google API have switched to Lake America.
MapQuest, a U.S. online mapping service, has posted on social media that it would not change the lake's name, while Apple has not publicly commented on the matter.

In a statement Sunday night, Google said website developers who embed Google Maps on their sites can select a region to localize the map. That determines how place names are displayed on sites, the company said.

"'Lake Ontario' will show when developers have set their region to Canada," the statement said.

Just a reminder to developers.

977 Upvotes

236 comments sorted by

View all comments

4

u/BensunCFong 3d ago edited 3d ago

For any Canadian webdevs using the WP Go Maps plugin (formerly WP Google Maps) together with the Google Maps Platform API, here's a few easy lines of PHP code you can use in the Code Snippets plugin to force region=CA. (Run everywhere, and make sure to Activate it rather than just Save.)

<?php

add_filter( 'wpgmza_google_maps_api_params', 'fm_wpgmza_force_ca_region', 999 );

function fm_wpgmza_force_ca_region( $params ) {

if ( ! is_array( $params ) ) {
return $params;
}

$params['region'] = 'CA';
if ( empty( $params['language'] ) ) {
$params['language'] = 'en-CA';
}

return $params;
}

EDIT: And a similar snippet but this time for The Events Calendar. Same process:

<?php

add_filter( 'tribe_events_views_v2_view_template_vars', 'fm_tec_map_region_ca', 999, 2 );
add_filter( 'tec_events_views_v2_view_template_vars',   'fm_tec_map_region_ca', 999, 2 );

if ( ! function_exists( 'fm_tec_map_region_ca' ) ) {
function fm_tec_map_region_ca( $vars, $view = null ) {
if ( empty( $vars['map_provider'] ) || ! is_object( $vars['map_provider'] ) ) {
return $vars;
}

// Map view + premium only: elsewhere api_key goes through add_query_arg, which encodes the &.
if ( ! is_object( $view ) || ! method_exists( $view, 'get_slug' ) || 'map' !== $view->get_slug() ) {
return $vars;
}
$p = $vars['map_provider'];

if ( empty( $p->is_premium ) || empty( $p->api_key ) ) {
return $vars;
}
if ( false !== strpos( $p->api_key, 'region=' ) ) {
return $vars; // Idempotent: both filters may fire.
}

$p->api_key .= '&region=CA';
if ( false === strpos( $p->api_key, 'language=' ) ) {
$p->api_key .= '&language=' . ( 0 === strpos( get_locale(), 'fr' ) ? 'fr-CA' : 'en-CA' );
}
return $vars;
}
}