-
Notifications
You must be signed in to change notification settings - Fork 15
PHP API
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.
There are various ways to query by location, especially with posts.
A subset of the TagReference#QueryVariables are used for a few kinds of geographical 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.
A query to find all posts/objects within a bounding latitude and longitude range is made using minlat, maxlat, minlng, and maxlng.
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).
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.
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}";
Geo Mashup behavior can be augmented with callbacks in the form of WordPress actions.
Called when Geo Mashup has loaded and its API is available for use.
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.
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' );
Called when an object location is created.
Arguments:
- $object_name - 'post', 'user', 'comment', etc.
- $object_id
- $geo_date
- $location - the location object added
Called when an object location is updated.
Arguments:
- $object_name - 'post', 'user', 'comment', etc.
- $object_id
- $geo_date
- $location - the location object updated
Called when a new location is added.
Arguments:
- location - the location added
Called when a new location is updated.
Arguments:
- location - the location updated
Called when an object location is deleted.
Arguments:
- object_location - the object location deleted
Called when an location is deleted.
Arguments:
- location - the object location deleted
Some Geo Mashup data can be altered using these WordPress filters.
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
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;
}
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
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';
}
} );
Modify the fields included in a map query.
Modify the tables joined in a map query.
Modify the where clause of a map query.
Modify the orderby clause of a map query.
Modify the limit clause of a map query.
Modify the HTML content of a map tag (usually an iframe in a div).
Arguments:
- $content - the map HTML.
Modify the query arguments before a geo search is performed.
Arguments:
- $query_args - array of TagReference#Query_Variables.
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;
}
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
- 'click_to_load' - true if click_to_load is enabled
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.