Skip to content
Dylan Kuhn edited this page Jun 20, 2019 · 5 revisions

The generated documentation covers all the classes and methods you can use.

Generated documentation doesn't include WordPress filters, so those are documented here along with some overviews and examples.

Geographical Queries

There are various ways to query by location, especially with posts.

Location query variables

A subset of the TagReference#QueryVariables are used for a few kinds of geographical queries.

Radius queries

A query to find all posts/objects within a distance from a search poing is made using near_lat, near_lng, and radius_km or radius_mi.

Bounding box queries

A query to find all posts/objects within a bounding latitude and longitude range is made using minlat, maxlat, minlng, and maxlng.

Named area queries

A query to find posts/objects in a named area is made using one of: admin_code (state/province), country_code, postal_code, or locality_name (city).

WP_Query Integration

Added in Geo Mashup 1.7.0.

Any of the location query variables can be used in a WP_Query post query with the geo_mashup_query variable. Here are some examples:

$nv_query = new WP_Query( array(
	'posts_per_page' => -1,
	'geo_mashup_query' => array(
		'admin_code' => 'NV',
	)
) );
$zip_query = new WP_Query( array(
	'posts_per_page' => -1,
	'geo_mashup_query' => array(
		'postal_code' => '96161',
	),
) );
$radius_query = new WP_Query( array(
	'posts_per_page' => -1,
	'geo_mashup_query' => array(
		'near_lat' => 39,
		'near_lng' => -120,
		'radius_km' => 50,
	),
) );

Any other WP_Query parameters can be added, allowing for powerful combinations.

The GM_Location_Query class

Added in Geo Mashup 1.7.0.

Geographical queries can be constructed for objects other than posts using this class, whose constructor takes an array of location query variables. An example of a user query:

$location_query = new GM_Location_Query( array(
	'minlat' => $nv_location->lat - 1,
	'maxlat' => $nv_location->lat + 120,
	'minlon' => $nv_location->lng - 1,
	'maxlon' => $nv_location->lng + 1,
) );

list( $cols, $join, $where, $groupby ) = $location_query->get_sql( $wpdb->users, 'ID' );

$sql = "SELECT {$wherepdb->users}.ID FROM {$wpdb->users}{$join} WHERE 1=1{$where}";

Actions

Geo Mashup behavior can be augmented with callbacks in the form of WordPress actions.

geo_mashup_init

Called when Geo Mashup has loaded and its API is available for use.

geo_mashup_render_map

Arguments:

  • $mashup_script - 'geo-mashup-mxn' or 'geo-mashup-google' for Google V2

Called when a map is being rendered and may be used to enqueue additional scripts.

Example

This is how a script is enqueued to add the blue dot to search results maps:

function prefix_geo_mashup_render_map() {
  if ( 'search-results-map' == GeoMashupRenderMap::map_property( 'name' ) ) {
	  GeoMashup::register_script( 'geo-mashup-search-results', 'js/search-results.js', array( 'geo-mashup' ), GEO_MASHUP_VERSION, true );
	  GeoMashupRenderMap::enqueue_script( 'geo-mashup-search-results' );
  }
}
add_action( 'geo_mashup_render_map', 'prefix_geo_mashup_render_map' );

geo_mashup_added_object_location

Called when an object location is created.

Arguments:

  • $object_name - 'post', 'user', 'comment', etc.
  • $object_id
  • $geo_date
  • $location - the location object added

geo_mashup_added_updated_location

Called when an object location is updated.

Arguments:

  • $object_name - 'post', 'user', 'comment', etc.
  • $object_id
  • $geo_date
  • $location - the location object updated

geo_mashup_added_location

Called when a new location is added.

Arguments:

  • location - the location added

geo_mashup_updated_location

Called when a new location is updated.

Arguments:

  • location - the location updated

geo_mashup_deleted_object_location

Called when an object location is deleted.

Arguments:

  • object_location - the object location deleted

geo_mashup_deleted_location

Called when an location is deleted.

Arguments:

  • location - the object location deleted

Filters

Some Geo Mashup data can be altered using these WordPress filters.

geo_mashup_load_location_editor

Allows you to load the location editor in places other than the default admin post editor and user profile forms. Many uses have been discussed for this, but the essence is that the scripts that power the location editor will only be enqueued when this filter return true.

Arguments:

  • $load_flag - whether to enqueue location editor assets

Example

This will load location editor assets for the BuddyPress front editor. Note that the editor markup must also be present in the form, which can be accomplished with this template tag: <?php echo GeoMashupUserUIManager::get_instance()->print_form(); ?>.


add_filter( 'geo_mashup_load_location_editor', 'filter_geo_mashup_load_location_editor' );

/**

 * Load location editor on the BuddyPress user profiles

 */

function filter_geo_mashup_load_location_editor( $load_flag ) {

    global $user_id;

    if ( bp_is_user_profile() ) {

	$user_id = bp_displayed_user_id();

        return true;

    } 

    

    return $load_flag;

}

geo_mashup_locations_json_object

Allows you to change the object data that gets sent to a map. Called once for each object.

Arguments:

  • $json_properties - an associative array of properties to include in the object, including object_id, lat, lng, title, author, categories
  • $queried_object - the query result row returned for the object

Example

Use the saved name instead of the default object title (post_title for posts).

function my_geo_mashup_locations_json_filter( $json_properties, $queried_object ) {
	$json_properties['title'] = $queried_object->saved_name;
	return $json_properties;
}
add_filter( 'geo_mashup_locations_json_object', 'my_geo_mashup_locations_json_filter', 10, 2 );

Now you can access the data in custom javascript:

GeoMashup.addAction( 'objectIcon', function( properties, object ) {
	// Use a special icon for the saved location 'Swimming Pool'
	if ( 'Swimming Pool' == object.title ) {
		object.icon.image = properties.template_url_path + 'images/pool_icon.png';
	}
} );

geo_mashup_locations_fields

Modify the fields included in a map query.

geo_mashup_locations_join

Modify the tables joined in a map query.

geo_mashup_locations_where

Modify the where clause of a map query.

geo_mashup_locations_orderby

Modify the orderby clause of a map query.

geo_mashup_locations_limits

Modify the limit clause of a map query.

geo_mashup_map_content

Modify the HTML content of a map tag (usually an iframe in a div).

Arguments:

  • $content - the map HTML.

geo_mashup_search_query_args

Modify the query arguments before a geo search is performed.

Arguments:

geo_mashup_search_query_location_text

Modify the geo search text before it is geocoded.

Arguments:

  • $location_text - the location search string

Example:

/* add country to the geo mashup search */
add_filter( 'geo_mashup_search_query_location_text', 'my_geo_mashup_search_query_location_text_filter');


function my_geo_mashup_search_query_location_text_filter($location_text){
    if(!is_string($location_text) ) {return; }
    $location_text = $location_text.',DE';

    return $location_text;
}

geo_mashup_static_map

Modify the image HTML for static maps.

Arguments:

  • $map_image - the HTML tag. Return your filtered version.
  • $map_data - An array of all data used to build the map.
  • $click_to_load - An array with click_to_load information:
    • 'click_to_load' - true if click_to_load is enabled
    • 'click_to_load_text' - the text specified for the click_to_load link

Dependent Plugins

There are good possibilites for companion plugins to make use of Geo Mashup data.

If you need a Google API Key in your plugin, you can get Geo Mashup's with this PHP code: $google_key = get_option( 'google_api_key' );. This setting is not deleted if Geo Mashup is uninstalled.