wpbdp_googlemaps_map_locations

Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Change any locations that have been prepared to show on the map. This hook runs right before the PHP is sent to the javascript that creates the map.

Usage

add_filter( 'wpbdp_googlemaps_map_locations', 'change_map_locations', 10, 2 );

Parameters

  • $locations (array) An array of addresses.
    • $locations['address'] (string)
    • $locations['geolocation'] (array) The latitude and longitude.
    • $locations['content'] (string) The content shown in the tooltip.
  • $args (array) All the settings that will be used to create the map

Examples

Change the image for the map pin

This example will replace the pin icon for the map location

add_filter( 'wpbdp_googlemaps_map_locations', 'my_custom_function' );
function my_custom_function( $locations ) {
	foreach ( $locations as $k => $l ) {
		$locations[ $k ]['icon'] = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'; //change this url with the path of the image you want to place
	}
	
	return $locations;
}

Change the longitude and latitude

this example will change the longitude and latitude on the map for a specific address

add_filter( 'wpbdp_googlemaps_map_locations', 'my_custom_function' );
function my_custom_function( $locations ) {
	foreach ( $locations as $k => $l ) {
		if ( $l['address'] === 'Alaska USA' ) { // replace Alaska USA with the address you want to change
			$locations[ $k ]['geolocation']->lat = '42.8400295'; // replace the latitude with the one you want to show on the map
			$locations[ $k ]['geolocation']->lng = '-85.5130942'; // replace the longitude with the one you want to show on the map
		}
	}
	
	return $locations;
}

Related Articles