Coding question for dynamic Gmap
-
Our agency provides a directory of resources (i.e., shelters and foodshelves) around the state for our clients. Each resource is recorded as a post in a unique category, and each resource has custom fields called “address”, “city”, “state”, and “zip”.
We would like to create a Google map that automatically populates the map by pulling the address info from the resource posts.
Of the Gmap plugins available, it seemed like the Phoogle Maps plugin would be easiest to modify for this purpose (https://www.chrisandabigail.com/).
This plugin relies on php execution within posts, and we got it to work by manually adding addresses in this format:
<?php addAddress("122 Main St, City, State, 54321"); showMap(); ?>
It seems like we should be able to pull in the addesses from the post custom fields, so that we won’t have to update the map every time we add a resource post. We installed the Get Custom Fields plugin from CF to assist.
Here’s the statement we came up with thus far:
< ?php $my_query = new WP_Query('cat=6'); ?>
< ?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
addAddress("< ?php echo c2c_get_custom('address'); ?>, < ?php echo c2c_get_custom('city'); ?>, < ?php echo c2c_get_custom('state'); ?>, < ?php echo c2c_get_custom('zip'); ?> " ,"< ?php the_title(); ?>");
< ?php endwhile; ?>
showMap();
This will print out the [ addAddress(“122 Main St, City, State, 54321”); showMap(); ], but it won’t execute the “addAddress” and “showMap” functions.
Any ideas on how to wrap the statment we’ve written thus far with another php statment to trigger the map?
Thanks in advance for any suggestions!
- The topic ‘Coding question for dynamic Gmap’ is closed to new replies.