Language for google maps

Home Forums Calendar Products Events Calendar PRO Language for google maps

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1191771
    Daan
    Participant

    Hi there,
    I would like to change the google maps language, but changing it in the main.php breaks the plugin.
    How should i go about replacing the function (with a filter maybe?) that does that from the functions.php

    What i want to change:

    		public function googleMapLink( $post_id = null ) {
    			if ( $post_id === null || ! is_numeric( $post_id ) ) {
    				global $post;
    				$post_id = $post->ID;
    			}
    
    			$locationMetaSuffixes = array( 'address', 'city', 'region', 'zip', 'country' );
    			$to_encode = '';
    			$url = '';
    
    			foreach ( $locationMetaSuffixes as $val ) {
    				$metaVal = call_user_func( 'tribe_get_' . $val, $post_id );
    				if ( $metaVal ) {
    					$to_encode .= $metaVal . ' ';
    				}
    			}
    
    			if ( $to_encode ) {
    				$url = 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=' . urlencode( trim( $to_encode ) );
    			}
    

    With hl=en i would like to change the language or the links.
    I couldn’t yet find how to change it for the maps themselves. Any help?

    Much obliged,
    Daan

    #1191772
    Daan
    Participant

    Ah, must be something in the src/functions/template-tags/google-map.php

    	/**
    	 * Google Map Embed
    	 *
    	 * Returns an embedded google maps for an event
    	 *
    	 * @category Events
    	 *
    	 * @param string $post_id
    	 * @param int    $width
    	 * @param int    $height
    	 * @param bool   $force_load If true, then load the map even if an address is not provided.
    	 *
    	 * @return string An iframe pulling http://maps.google.com/ for this event
    	 */
    	function tribe_get_embedded_map( $post_id = null, $width = null, $height = null, $force_load = false ) {
    		return Tribe__Events__Embedded_Maps::instance()->get_map( $post_id, $width, $height, $force_load );
    	}
    

    How would I fit in the string: &language=nl
    https://developers.google.com/maps/documentation/javascript/examples/map-language

    Thanks!

    #1192363
    Josh
    Participant

    Hey Daan,

    Thanks for reaching out to us!

    Sure thing! You can modify the map language using the modified URL using the “tribe_events_google_map_link” filter.

    I’m not sure if this would be 100% exactly what you’re looking for here but this would be an example of how to extend that link here:

    https://gist.github.com/BeardedGinger/36200f93c33dfe9848a8294319f72e63

    Let me know if this helps.

    Thanks!

    #1193448
    Daan
    Participant

    Hi Josh,

    That works great for the link to googlemaps! Thanks.
    At least when i replace ‘&language=nl’ with ‘&hl=nl’. 🙂

    But… not so much for the embedded map.
    I guess (but not sure) the string ‘&language=nl’ should be added to the Tribe__Events__Embedded_Maps::instance().
    But i don’t quite get how i should get that to work.
    Maybe you could shed some light into my darkness? Owhhhh! (My best wolf imitation.)

    Regards,
    Daan

    #1194403
    Josh
    Participant

    Hey Daan,

    Thanks for following up!

    Looking at our source code, I’m not seeing a straightforward way to filter or modify the language for the embedded map there. I’ll need to do a little more research there to see what I can find for you.

    Thanks!

    #1194406
    Daan
    Participant

    Hi Josh!

    Thanks for letting me know you’re on to it!
    Exactly my thoughts up to ‘a little more research’ where i gave up and asked. 🙂

    Hope to hear for you soon!
    Daan

    #1195277
    Josh
    Participant

    Hey Daan,

    I’ve got an internal support ticket open for you here and will let you know what I hear back.

    Thanks!

    #1196949
    Daan
    Participant

    Thanks Josh!
    That’s good news.
    Daan

    #1200805
    Josh
    Participant

    Hey Daan,

    I apologize for the delay here and appreciate your patience.

    It looks like we may have a filter that will work for you here! You can use the “tribe_events_google_maps_api”. With that, you should be able to add a query argument for the URL used and pass it for the embedded map.

    You could try something like:

    
    add_filter( 'tribe_events_google_maps_api', 'language_filter_embedded_map' );
    function language_filter_embedded_map( $js_maps_api_url ) {
    $js_maps_api_url = add_query_arg( 'hl', 'nl', $js_maps_api_url );
    return $js_maps_api_url ;
    }
    

    Let me know if this helps.

    Thanks!

    #1205829
    Daan
    Participant

    Almost there Josh,

    It’s like this:

    // gmap in nl :-3
    add_filter( 'tribe_events_google_maps_api', 'language_filter_embedded_map' );
    function language_filter_embedded_map( $js_maps_api_url ) {
    $js_maps_api_url = add_query_arg( '&language', 'nl', $js_maps_api_url );
    return $js_maps_api_url;
    }

    But then the main map is still in English.
    Hhmm, someone didn’t follow protocol.
    Could you check that out?

    Thanks & regards,
    Daan

    • This reply was modified 9 years, 5 months ago by Daan. Reason: typo
    #1206895
    Josh
    Participant

    Hey Daan,

    Thanks for following up here! I tested out the snippet and it appears to be working for me on the embedded maps https://cloudup.com/cqFyR1EKn97.

    Where are you currently adding that snippet?

    Thanks!

     

    #1207004
    Daan
    Participant

    Hi Josh,

    We also needed to add:
    add_filter( 'tribe_events_pro_google_maps_api', 'language_filter_embedded_map' );
    Else the main map remains without the language string.

    So the full code now is:

    // gmap in set language
    add_filter( 'tribe_events_google_maps_api', 'language_filter_embedded_map' );
    add_filter( 'tribe_events_pro_google_maps_api', 'language_filter_embedded_map' );
    function language_filter_embedded_map( $js_maps_api_url ) {
    $js_maps_api_url = add_query_arg( '&language', 'nl', $js_maps_api_url );
    return $js_maps_api_url;
    }

    But just now i saw that the single-events map doesn’t work on my mobile device.
    Could you look into that? Or should i open another ticket.

    Hhmm, would be great to have the static map on mobile or under a certain screen width.
    https://developers.google.com/maps/documentation/static-maps/

    Regards,
    Daan

    #1207679
    Josh
    Participant

    Hey Daan,

    Awesome! I’m glad you were able to get the map working with the different language!

    Might be best to open a new thread for that particular issue. In that thread, be sure to give full detail on the issue you’re experiencing along with verifying the Testing for Conflicts procedures so we can help you get to the root of that one more quickly.

    Thanks!

    #1215840
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Language for google maps’ is closed to new replies.