WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: The Events Calendar] Google map not showing (24 posts)

  1. AntonLargiader
    Member
    Posted 4 years ago #

    Other than checking the box in the settings screen, what is needed for Google Maps? How does one find the map; all I have is the List and Calendar tabs.

    Do I need a separate Google Maps plug-in?

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. AntonLargiader
    Member
    Posted 4 years ago #

    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.

  3. AntonLargiader
    Member
    Posted 4 years ago #

    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.

  4. Shane Pearlman
    Modern Tribe
    Posted 4 years ago #

    Thanks Anton,

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

    -S

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

  5. AntonLargiader
    Member
    Posted 4 years ago #

    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="http://maps.google.com/maps/api/staticmap?size=640x400&maptype=roadmap&markers=22901&markers=94954&sensor=false" />

    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.

  6. travellers
    Member
    Posted 4 years ago #

    @ 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!

  7. AntonLargiader
    Member
    Posted 4 years ago #

    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 = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=";
    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.

  8. AntonLargiader
    Member
    Posted 4 years ago #

    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.

  9. Anonymous
    Unregistered
    Posted 4 years ago #

    Thanks Anton, this works great now!

  10. AntonLargiader
    Member
    Posted 4 years ago #

    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.

  11. travellers
    Member
    Posted 4 years ago #

    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 google.com to google.co.uk 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!

  12. AntonLargiader
    Member
    Posted 4 years ago #

    Even in Google.com 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?

  13. travellers
    Member
    Posted 4 years ago #

    @ Anton
    Yes the postcode takes you direct to Beninborough in a map from either Google.com or Google.co.uk, 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 = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=";
    		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

  14. AntonLargiader
    Member
    Posted 4 years ago #

    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.

  15. AntonLargiader
    Member
    Posted 4 years ago #

    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).

  16. travellers
    Member
    Posted 4 years ago #

    Anton
    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!

  17. travellers
    Member
    Posted 4 years ago #

    Anton
    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!

  18. AntonLargiader
    Member
    Posted 4 years ago #

    Read the third post again. It describes the general logic of what I did. If you don't have similar code for line 60 then look around a bit. For me, it was line 60. The line you cite is line 24 for me. Maybe you have a lot of word wrapping going on. Maybe we're using different versions of the code.

    This line controls the presence of the address block on the display. If you really don't understand the php code you might not be able to get anywhere. In that case, hopefully a new release will come out soon with a similar modification.

  19. travellers
    Member
    Posted 4 years ago #

    Don't think the line numbering difference is caused by word wrapping or whatever because my line numbers (almost*) match up with yours in t-e-c.php. Maybe you're right and we're running different version numbers. For anyone following behind me, the line number in list.php that matches yours is line 95.

    *The 'almost' is in t-e-c.php - you suggested lines 1328 and 1329 (correct) but also lines 1371 and 1372 when in my installation it was lines 1370 and 1371. However, it works! You still need to enter at least some of the other fields, because if you enter just the postcode alone there's no map, but once you've entered some additional fields you get the correct map. Well done Anton for your investigative work and many thanks for your perseverance :)

  20. sammathews
    Member
    Posted 4 years ago #

    I know this is a little off topic, but I'm extremely noob to WP, I've got the events calender working, but how do i get it to show up in the menu options haha.. Do i create a page?

  21. Steve Weblin
    Member
    Posted 4 years ago #

    You need the menu item to link to the category page where the calender displays. http://www.yourdomain/category/events/month/

  22. justinendler
    Member
    Posted 4 years ago #

    @AntonLargiader - Thanks for the work!

    I've changed how this works. Since Google maps will produce relevant domestic and international maps with only a postal code, that is now all that is required to produce the map link. I'm not posting the fix here because it's over too many files:
    http://plugins.svn.wordpress.org/the-events-calendar/trunk/the-events-calendar.php
    http://plugins.svn.wordpress.org/the-events-calendar/trunk/views/list.php
    http://plugins.svn.wordpress.org/the-events-calendar/trunk/views/single.php

    Also, the function tec_event_address() now handles echoing the address, which simplifies the view files.

    The fix is committed to trunk, so you can grab the files above if you want.

    Multiple events per map is a great idea, but not handled in this fix.

    Justin

  23. silvafer
    Member
    Posted 4 years ago #

    Would it be possible to use latitude / longitude as an alternative to an address?

  24. patsar
    Member
    Posted 4 years ago #

    Justin,

    I try your solution and it works. But the calendar view is now broken. There are 2 undefined functions:
    1) In the gridview.php the loadStylesAndScripts()
    2) In the datepicker.php the getCategoryBase()

    I replaced loadStylesAndScripts() with loadDomainStylesScripts() but I can't figure out how to handle getCategoryBase()

Topic Closed

This topic has been closed to new replies.

About this Topic