Get Directions link in sidebar widget

This topic contains 15 replies, has 2 voices, and was last updated by  Joy 8 years, 2 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #125395

    Joy
    Buyer
    Post count: 1076

    Hello, I see that this has been requested before and this code will provide a text link that will open up Google Maps for directions:

    
    
    add_action('geodir_after_detail_page_more_info' , 'buttonmap', 10);
    function buttonmap(){
    global $post, $wp_query, $preview, $geodirectory;
    $postid = $wp_query->post->ID;
    $address= geodir_get_post_meta($postid,'post_address',true); //address
    $e_add = str_replace(' ', '+', $address); // + in space eg road+street+23
    
    $lat= geodir_get_post_meta($postid,'post_latitude',true); //lat
    $lon= geodir_get_post_meta($postid,'post_longitude',true); //lon
    //echo $e_add.$lat.$lon;
    
    echo "<a href="http://maps.google.com/maps?z=12&t=m&q=loc:".$lat."+".$lon."" target="_blank"> Mostra en Google Maps</a>";
    } 
    

    However, is it possible to add the address box and the Get Directions button to the sidebar widget – the same that appears on the Maps tab on the listing details? Thank you.

    #125908

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    this should do it:

    
    
    add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',2);
    
    function sd_map_in_detail_page_sidebar()
    {
     
        global $post, $post_images, $video, $special_offers, $related_listing, $geodir_post_detail_fields;
     
        $post_id = !empty($post) && isset($post->ID) ? (int)$post->ID : 0;
        $request_post_id = !empty($_REQUEST['p']) ? (int)$_REQUEST['p'] : 0;
        $is_backend_preview = (is_single() && !empty($_REQUEST['post_type']) && !empty($_REQUEST['preview']) && !empty($_REQUEST['p'])) && is_super_admin() ? true : false; // skip if preview from backend
     
        if ($is_backend_preview && !$post_id > 0 && $request_post_id > 0) {
            $post = geodir_get_post_info($request_post_id);
            setup_postdata($post);
        }
     
        $geodir_post_detail_fields = geodir_show_listing_info('detail');
     
        if (geodir_is_page('detail')) {
     
            $map_args = array();
            $map_args['map_canvas_name'] = 'detail_page_map_canvas';
            $map_args['width'] = '300';
            $map_args['height'] = '400';
            if ($post->post_mapzoom) {
                $map_args['zoom'] = '' . $post->post_mapzoom . '';
            }
            $map_args['autozoom'] = false;
            $map_args['child_collapse'] = '0';
            $map_args['enable_cat_filters'] = false;
            $map_args['enable_text_search'] = false;
            $map_args['enable_post_type_filters'] = false;
            $map_args['enable_location_filters'] = false;
            $map_args['enable_jason_on_load'] = true;
            $map_args['enable_map_direction'] = true;
            $map_args['map_class_name'] = 'geodir-map-detail-page';
     
        } elseif (geodir_is_page('preview')) {
     
            global $map_jason;
            $map_jason[] = $post->marker_json;
     
            $address_latitude = isset($post->post_latitude) ? $post->post_latitude : '';
            $address_longitude = isset($post->post_longitude) ? $post->post_longitude : '';
            $mapview = isset($post->post_mapview) ? $post->post_mapview : '';
            $mapzoom = isset($post->post_mapzoom) ? $post->post_mapzoom : '';
            if (!$mapzoom) {
                $mapzoom = 12;
            }
     
            $map_args = array();
            $map_args['map_canvas_name'] = 'preview_map_canvas';
            $map_args['width'] = '300';
            $map_args['height'] = '400';
            $map_args['child_collapse'] = '0';
            $map_args['maptype'] = $mapview;
            $map_args['autozoom'] = false;
            $map_args['zoom'] = "$mapzoom";
            $map_args['latitude'] = $address_latitude;
            $map_args['longitude'] = $address_longitude;
            $map_args['enable_cat_filters'] = false;
            $map_args['enable_text_search'] = false;
            $map_args['enable_post_type_filters'] = false;
            $map_args['enable_location_filters'] = false;
            $map_args['enable_jason_on_load'] = true;
            $map_args['enable_map_direction'] = true;
            $map_args['map_class_name'] = 'geodir-map-preview-page';
     
        }  
         if (geodir_is_page('detail') || geodir_is_page('preview')) {?>
    	<div class="sd-map-in-sidebar-detail"><?php geodir_draw_map($map_args);?>
     
    </div>
    <?php } }
    

    Let us know how you went,

    Thanks

    #125976

    Joy
    Buyer
    Post count: 1076

    Hi Paolo. Thank you but it didn’t work out. It places the map/button on the top of the sidebar and the loading icon just keeps spinning and spinning. I’ve also tried to put the code directly into a php widgets and am getting the following error:

    Parse error: syntax error, unexpected ‘}’ in /home/luckywel/public_html/wp-content/plugins/php-code-widget/execphp.php(27) : eval()’d code on line 74

    #126615

    Paolo
    Site Admin
    Post count: 31206

    To make it appear at the bottom of the detail sidebar you need to change the priority used, for example:

    from

    add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',2);

    to

    add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',10);

    If it doesn’t work probably there is an issue with some other code.

    We’d need to check you website to let you know. PHP widgets are not a good practice and i don’t think you can stick a function in it.

    Let us know,

    Thanks

    #126627

    Joy
    Buyer
    Post count: 1076
    This reply has been marked as private.
    #127095

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    the code i gave you works on the child theme I’m building so I’m not sure where the problem could be.

    I’ve passed this to Stiofan.

    Thanks for your patience,

    #127098

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    you just needed to exlude it from GD>Desing>details>hide tabs

    Thanks

    #127122

    Joy
    Buyer
    Post count: 1076

    Thank you, it cannot be in both the tabs and the sidebar at the same time?

    #127145

    Paolo
    Site Admin
    Post count: 31206

    The function I gave you is to move the map of the tab to the sidebar to have the get direction tool.

    You can have it in tab and sidebar if in the sidebar you use the widget.

    Thanks

    #127146

    Joy
    Buyer
    Post count: 1076

    The widget only shows the map. I am trying to append the text box and the get directions to both the listing tab and a sidebox. Is this possible?

    Thank you.

    #127150

    Paolo
    Site Admin
    Post count: 31206

    No it is not.

    The get direction part belongs to the tabs map.

    You can’t mix it with the widget map. They are 2 different set of functions.

    Thanks

    #127155

    Joy
    Buyer
    Post count: 1076

    Thank you for explaining that. I have two last concerns:

    1. How to disable the mouse scrolling
    2. I have a widget that I would like to place BEFORE this map. I’ve moved the map to the end of the details listing, is there a way that my widget can be placed before the map? The widget is set in the “GD Detail Listing” sidebar. I don’t know if they respect the priority settings.

    #127325

    Paolo
    Site Admin
    Post count: 31206

    1) have you tried adding a new arg to the map function?

    $map_args['scrollwheel'] = false;

    2) try increase from 10 to 30:

    add_action( 'geodir_detail_sidebar_inside', 'sd_map_in_detail_page_sidebar',30);

    Let us know,

    Thanks

    #127327

    Joy
    Buyer
    Post count: 1076
    This reply has been marked as private.
    #127329

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    You cannot add the map in between widgets like that. If you want the map in between widgets you must use the map widget.

    Thanks

Viewing 15 posts - 1 through 15 (of 16 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket