Skip Navigation

How to Use Google Maps API from China in WordPress

When using Toolset Maps with the Google Maps API, you have to update your theme to be able to use it in the People’s Republic of China. In this lesson, we explain how to do this.

Toolset Maps loads Google Maps resources, which are used for rendering the maps and the related information on them. People’s Republic of China has some specific rules for loading Google APIs in that country. They are required to be loaded from the Chinese Google domain – google.cn. If you are using Toolset Map plugin in China, there are two additional hooks you need to add to your theme’s functions.php file.

add_filter( 'toolset_filter_toolset_maps_api_js_url', 'prefix_serve_maps_js_from_china' );
 
function prefix_serve_maps_js_from_china( $url ) {
$url = 'http://maps.google.cn/maps/api/js';
return $url;
}
 
add_filter( 'toolset_filter_toolset_maps_api_geocode_url', 'prefix_serve_maps_geocode_from_china' );
 
function prefix_serve_maps_geocode_from_china( $url ) {
$url = 'http://maps.google.cn/maps/api/geocode/json';
return $url;
}

This code will ensure that the Chinese domain is used for loading Google Maps API. Please note that you need to use Toolset Maps plugin version 1.1 or higher for this to work.

If you are using Azure Maps API there is no need for any changes to your theme’s functions.php file.

Updated
novembre 16, 2020