Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

GeoMashup Plugin - Legend with post types instead of categories WordPress


This is a question for GeoMashup plugin.

I have global and contextual maps in which many posts are displayed belonging to different custom post types and custom taxonomies. I do not use standard post types at all.

The query I am using for displaying maps of this type is the following (I'm not sure if it's the best/most appropriate way, but it works):

$current_location =
GeoMashupDB::get_post_location( get_the_ID() );
query_posts(array( 'post_type' => array( 'restaurant', 'hotel',
'bar', 'shop'... [etc.] ) ));
echo GeoMashup::map('near_lng='.$current_location-
>lat.'&map_content=contextual&radius_km=10&height=200&width=400' );

Now, what I want to achieve is to display a legend for the custom post types displayed. Suppose I have restaurants, hotels, bars, shops etc. in the map. These are post types, not categories or terms in a custom taxonomy. I want to have a legend with labels displaying the post types I'm querying in my maps and be able to toggle the display of each post type in my map (with a button matching the legend label).

here you can find a live website with something similar I want to
achieve [[LINK href=" "]] [[/LINK]]


Answers (2)


Arnav Joy answers:

For legend

place this after query_posts(...);

<?php echo "Legend==".$post->post_type ; ?>

Gaslight comments:

sorry but this is not working, if I place that as you suggested all I get is an echo of the post type of the current item

for example, I have a contextual map showing an event (post type); map is centered on where the event takes place; it is surrounded by markers belonging to other post types. My legend should include all the other post types minus the event post type in this case.

If I use your code, I get echoed only the post type of the current event, not all the others, plus this doesn't solve the part of my question where I would like to toggle the markers on my map

thank you anyway and happy new year

Arnav Joy comments:

can you provide the url of your site.

Gaslight comments:

it's not online, I'm developing on local machine before going live

from the query above you can see the way I'm calling a contextual map, I haven't touched GeoMashup plugin (latest build) - I'm running WP3.3 multisite

Arnav Joy comments:

ok , then

can you provide a screenshot of currently running site with some labels into it.

Gaslight comments:

what labels? I want to create the labels, there no labels because the GeoMashup function to create a map legend currently works only with post categories, while I am using neither (I have custom post types and custom taxonomies) - I've read that is possible to do what I want but needs some customisation with json and php, I don't know how to do it and the documentation I've found is poor


Gaslight comments:

this is all the relevant code for this question, the rest has nothing to do with GeoMashup

<?php // get the current post ID
$current_post = get_the_ID();
// get coordinates for current post
$current_location = GeoMashupDB::get_post_location( get_the_ID() );
// get current post parent location to broaden query results
$current_area = get_the_terms($current_post, 'sg_taxon_location');
$query_area = $current_area[0]->category_parent;
// query posts for related content in contextual map
query_posts( array( 'post_type' => array( 'accommodation', 'hiking', 'heritage', 'nightlife', 'dining', 'shopping' ), 'sg_taxon_location' => $query_area ));
// display the contextual map with related posts
echo GeoMashup::map('center_lat='.$current_location->lat.'&center_lng='.$current_location->lng.'&marker_select_center=true&object_ID='.$current_post.'&open_object_id='.$current_location->object_id.'&near_lng='.$current_location->lng.'&cluster_max_zoom=14&near_lat='.$current_location->lat.'&legend=dl&interactive_legend=true&name=&event&map_content=contextual&radius_km=100&add_google_bar=false&height=310&width=470' );
// reset the query to prevent mess with main query for current post
wp_reset_query(); ?>

Arnav Joy comments:

actually i want to see what is visible in the site and how it looks , give the screenshot of the page where you have called this code.

Gaslight comments:

this is what the code above outputs

as you can see it's just a contextual map - I haven't customized the markers yet. it is centered on the current item (post type, single view)

there's nothing else to add, the rest is not related to GeoMashup or relevant to my question

you can see what I want to achieve in a external third party website: (which does not use GeoMashup but it's developed on top of Google Maps API like GeoMashup)

GeoMashup has a built in function to display categories as a legend, but I don't need that and I don't want that - I need to list labels for post types appearing in my GeoMashup map and be able to toggle appearance of related markers by clicking on them