Support » Plugins » [Plugin: The Events Calendar] Google map not showing

Viewing 15 replies - 1 through 15 (of 23 total)
  • I guess I figured this out… I have to have a street address. That’s kind of a pain, because these events don’t necessarily have a street address. The goal is that the user can look at a map of the country and see what events are nearby but the way I see it, this functionality is just not provided.

    Without the street address I never even got the Google Map link.

    It would be nice if:

    1) a street address weren’t needed. Google Maps can find an address with just a zip code so it should be possible for TEC to find it with a town, state and ZIP.

    2) there were a third tab for “Map” so that the user can see a map covering all of the events, at least the future ones. As it is now, the map for each event doesn’t show any other events.

    OK I dug into this a bit. For those of you who want a bit more flexibility in the mapping, here are some notes.

    In list view, the address doesn’t show unless all address fields are filled in. This is from a conditional statement in list.php; I edited it to remove the need for @address around line 60. Now I get partial addresses and Gmaps links for everything.

    But the Gmaps links won’t work because without all of the fields no URL is generated. So in the-events-calendar.php look around lines 1326 and 1369 and you’ll see why. Again I removed the $address requirements.

    Now I get maps for everything. Some events have no street address (graduation weekend, air races, Macy’s parade) and a more broad definition of location is OK or even better. The downside is that you will always have a point on the Gmap for the event even if it doesn’t mean anything. You’re at Google’s mercy on that one.

    Better would be to re-write the code to provide for better accuracy when the additional fields are present without breaking when they weren’t. Not too hard, just more conditionals. I might do that later on but for now these maps do what I need.

    Now to figure out a way to get a single map of multiple events.

    Shane Pearlman


    Modern Tribe

    Thanks Anton,

    We’ll loosen the restrictions on the address for the next release.


    Looking for news and tips about our open source plugins? Follow Shane on twitter @justlikeair.

    Onto the next phase: I don’t have time to work this out yet but if I have multiple ZIP codes (22901 and 94954 for example) I can easily create a map showing both of them:
    <img src="" />

    So the next challenge is to query the list of events and generate that URL string. I suspect I’m going to end up going in a different direction because this is just a static map without links on the markers, but it’s a learning experience. I’ll probably end up digging deeper into the Google Maps API.

    Then I’ll embed that map at the top of the events category page so that each marker links to the appropriate event post.

    @ Anton
    I’m with you in that some of my events don’t have a physical street address which is making an embedded map difficult. A standard Google map is locating them fine from just a postcode (the UK version of a ZIP), but even with the postcode defined in TEC the result is simply a map of America.

    I was quite excited when I found your post as I thought I’d be able to edit out the requirement for all fields and let Google deliver the map based solely on the postcode, but looking at the lines you suggest I can’t see what to edit – any chance you could post them here so we could all see it?

    Oh, and I’m also with you about an ‘overall’ view map showing all future events on it too – please feedback here on how you get on with that as I’d love to do similar!

    but looking at the lines you suggest I can’t see what to edit – any chance you could post them here so we could all see it?

    At line 1325 I now have this:

    $google_url = "";
    if ( $country == "United States" && !empty( $city ) && !empty( $state) && !empty( $zip ) ) {
       return $google_url . urlencode( $city . " " . $state . " " . $zip . " " . $country);
    elseif ( !empty( $country ) && !empty( $address ) && !empty( $city ) && !empty( $province ) && !empty( $zip ) ) {
       return $google_url . urlencode( $address . " " . $city . " " . $province . " " . $zip . " " . $country);

    1) starts the Google URL
    2) if all of those fields are filled in and we’re in the US, add them to the URL and return it
    3) if all of those fields are filled in and we’re elsewhere, add them to the URL and return it

    I took the $address sections out of the US-specific part but left them in the International part (look at the difference). You can probably pare it down to just postal code, or at least postal code and state.

    That’s just the part in t-e-c.php. You need to do something similar in the template to allow the Google Maps button to show up in the first place without all of the fields being filled in. It works the same way but if you want an example let me know.

    Probably the best way to recode this (down the road) is to eliminate the identical checks in the template and in the functions file. Establish one way to determine if you’re going to have a GMaps button and then just use that for validation everywhere.

    Oh, and I’m also with you about an ‘overall’ view map showing all future events on it too – please feedback here on how you get on with that as I’d love to do similar!

    I’ll start a separate thread for that, where we can collect more ideas.

    Thanks Anton, this works great now!

    Cool. Remember there’s another similar section below it. If you look back at my earlier post I refer to lines 1326 and 1369. The example I gave above was just for section around line 1326 [get_event_google_map_link()] but you might want to change section around line 1369 [get_event_google_map_embed()] as well.

    I was really hoping this would work for me but no joy 🙁
    Perhaps it only works with US Zips, but I edited as per your edits above and still generated just a country-wide US map for a place called Beningborough Hall by just entering the postcode YO30 1DD. I did try changing the to too, because if I enter that postcode in Google Map UK it gets the address fine, but still no joy.

    Thing is, most of our events are in fields or whatever and don’t actually have a full address – a postcode is often all we have. Frustrated as hell now, especially seeing as it obviously works for RageBanken!

    Even in that takes me straight to Beningbrough Hall. I haven’t tested it but it seems the following edit would work. I think I would leave country in there, around 1327 or so:

    elseif ( !empty( $country ) && !empty( $zip ) ) {
       return $google_url . urlencode( $zip . " " . $country);

    And then again in the next section around 1371.

    What code do you have there?

    @ Anton
    Yes the postcode takes you direct to Beninborough in a map from either or, but they don’t do that in a TEC version of a Google map – you just get a whole USA map.

    The code I have in there is completely standard and unmodified as here:

    $google_url = "";
    		if ( $country == "United States" && !empty( $address ) && !empty( $city ) && !empty( $state) && !empty( $zip ) ) {
    			return $google_url . urlencode( $address . " " . $city . " " . $state . " " . $zip . " " . $country);
    		} elseif ( !empty( $country ) && !empty( $address ) && !empty( $city ) && !empty( $province ) && !empty( $zip ) ) {
    			return $google_url . urlencode( $address . " " . $city . " " . $province . " " . $zip . " " . $country);
    		return "";

    for lines 1325-1332, and:

    if ( $country == "United States" && !empty( $address ) && !empty( $city ) && !empty( $state) && !empty( $zip ) ) {
    				$googleaddress = urlencode( $address . " " . $city . " " . $state . " " . $zip . " " . $country);
    			} elseif ( !empty( $country ) && !empty( $address ) && !empty( $city ) && !empty( $province ) && !empty( $zip ) ) {
    				$googleaddress = urlencode( $address . " " . $city . " " . $province . " " . $zip . " " . $country);

    for lines 1369 to 1373. If I change them both to the code you suggested then no map is displayed at all – we’re back to the requirement of a TEC map to have every field filled in

    The stuff that says “&& !empty(whatever)” says that the URL will not be modified if those fields are empty. Your address fields are empty. You can’t leave that stuff in there for fields that won’t have a value in them.

    What is your code up around line 60 now?

    EDIT: I meant line 60 on the template. If you change this properly, you will get the address and GM button on the page even when you only have partial fields. Lines 13xx in t-e-c.php control how the GM URL is modified to add address parameters.

    Do this:

    In list.php change line 60 to this:
    if (!empty( $city ) || !empty( $state ) || !empty( $zip ) ) :

    That says to display the address and GM button if you have ANY of those fields, rather than if you have all of them.

    In t-e-c.php change lines 1328 and 1329 to read:

    } elseif ( !empty( $country ) && !empty( $zip ) ) {
       return $google_url . urlencode( $zip . " " . $country);

    And change lines 1371 and 1372 to read:

    } elseif ( !empty( $country ) && !empty( $zip ) ) {
       $googleaddress = urlencode( $zip . " " . $country);

    It works for me. I used a hyphen in your postcode so you may want to try that also (or first, if you think you have already made the necessary code changes).

    I need to modify list.php? As in /THEME/events/list.php? Okay, no problem, just that nobody up to now has mentioned editing in any other file than t-e-c.php!
    Line 60 in list.php is this:

    <?php the_title('<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></h2>'); ?>

    I’m not sure that’s where you’re intending me to edit as there’s no if/else statement there to modify!

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘[Plugin: The Events Calendar] Google map not showing’ is closed to new replies.