Forums › Forums › Search & Filter Pro › Google map API integration
Tagged: google maps
- This topic has 10 replies, 3 voices, and was last updated 7 years ago by Trevor.
-
Trevor(Private) October 18, 2017 at 5:45 am #137066
There are two possible uses of a map.
One is where you do a geo location search (e.g. find properties within 20km of location xxx). The other is where you show locations on a map, but search for some other than geo location.
As of yet, we do not support geo location. But it IS possible to show either static or interactive Google Maps based on data held in posts (but not filter that location data).
Anonymous(Private) October 18, 2017 at 8:16 am #137079“The other is where you show locations on a map, but search for some other than geo location.”
Yes, the search criteria are not geo. For instance, the map will show locations of every post made by one author. I’m using the pro version of the plugin. Is there a callback, hook or something like that I could use to ajax refresh the map along with the new results?
Thanks
Trevor(Private) October 18, 2017 at 8:39 am #137081This is something that I have looked at before. The questions is, how to refresh the map. Most map plugins do not have the means to do this, and to make a hook for each plugin is not practical.
How I solved it was that I have a developer license for https://www.wpgmaps.com/
In the future, they are extending how they support posts and pages, but it is at the early stage right now.
What you need is your post (as you have), with a custom field for the map ID. For each post, you need to make a map. You have lost of details that you can add here, but, sadly, this is not (yet) linked to what might be the same detail in a post). To be able to click from the map to the post, you have to add the full URL.
Additionally, you need a base map, on to which the results page would add the markers for all the results posts.
Then you add a ‘mashup’ shortcode (or PHP do_shortcode() function) to the page. In the middle of this you need a comma separated list of map ID’s for the results posts. For this you will need to fetch the list of ID’s. If you want to do this, I am willing to work with you to show you (and other users how). I would prefer to use our shortcode method to make this.
Anonymous(Private) October 18, 2017 at 11:07 pm #137280Hi, I’m not using a plugin for the map. That’d complicate things no? I intend to do it in Javascript and manipulate the marker array directly on the page similar to this. https://codepen.io/mikejandreau/pen/qXwYGZ
What do you think? Does it seem feasible with the code base?Thanks
Anonymous(Private) November 1, 2017 at 7:27 pm #139694Hi Trevor,
Thanks to your amazing help, I was able to also make something like this work with that maps plugin you mention above.
Here’s the maps code I placed on the results.php page in my child theme (the ACF field for the map ID is called “hotel_map_id”):
<?php
$map_sc_text='[wpgmza id=”5″ mashup=true mashup_ids=”‘;while ($query->have_posts())
{
$query->the_post();?>
<div>
<h2>“><?php the_title(); ?></h2><p><br /><?php the_excerpt(); ?> </p>
<?php
if ( has_post_thumbnail() ) {
echo ‘<p>’;
the_post_thumbnail(“small”);
echo ‘</p>’;
}
?>
<p><?php the_category(); ?></p>
<p><?php the_tags(); ?></p></div>
<hr />
<?php$map_sc_text.=get_field(‘hotel_map_id’).’,’;
}$map_sc_text.='” parent_id=”5″]’;
do_shortcode($map_sc_text);?>
However, even though the functionality is perfect, I now get this error (only on the search and results page, not the whole site):
Warning: Invalid argument supplied for foreach() in /wp-content/plugins/wp-google-maps-pro/wp-google-maps-pro.php on line 3570.
Did you by any chance come across this issue when you were doing this? If so, how did you fix it?
Thank you so so much!
Maria
Trevor(Private) November 2, 2017 at 12:13 pm #139818Hi
Your code isn’t inside back ticks (code ticks) so it is hard to read, so I have recoded it here, and towards the end added a line to remove the final comma that the code adds (it adds the ID plus a comma each time, but the last comma is not needed):
<?php $map_sc_text='[wpgmza id="5" mashup=true mashup_ids="'; while ($query->have_posts()) { $query->the_post(); ?> <div> <h2><?php the_title(); ?></h2> <p><br /><?php the_excerpt(); ?> </p> <?php if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small"); echo '</p>'; } ?> <p><?php the_category(); ?></p> <p><?php the_tags(); ?></p> </div> <hr /> <?php $map_sc_text.=get_field('hotel_map_id').','; } $map_sc_text=substr($map_sc_text,0,-1); $map_sc_text.='" parent_id="5"]'; do_shortcode($map_sc_text); ?>
Does that work?
-
AuthorPosts