"Get Directions" button to Open Google Maps Link

This topic contains 15 replies, has 7 voices, and was last updated by  Lee Sapara 7 years, 9 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #232446

    Lee Sapara
    Expired Member
    Post count: 7

    Hi!

    I have been reading about this and from what I can find it has been a dead end and could not post to anything relevant that was still open; I encourage Palo to read this.

    In Reference to Posts:
    https://wpgeodirectory.com/support/topic/detail-listing-page-get-direction-function-is-missing/
    https://wpgeodirectory.com/support/topic/simpler-directions-for-mobile/
    https://wpgeodirectory.com/support/topic/mobile-device-issues/

    I understand the sending of the users location through the phone to give directions on the mobile device thru the website is not possible as it doesn’t give the persice cordinated of the persons actual location. —But could the “Get Directions” Button Link just go to the Destination as the following link http://maps.google.com/?q=<<INSERT LAT FROM DB HERE>>+<<INSERT LONGITUDE FROM DB HERE>> ??

    So to get to Google 37.421854, -122.084112 the Link http://maps.google.com/?q=37.421854,-122.084112 should get us live directions from where I am if you got this on mobile.

    This should trigger a mobile device to open the link in the native Google Maps App where the device can get the users precise location they just need to click the get direction button again once the Destination point has loaded.

    On a Side note — I have a plugin installed on my WordPress that forces any external link to open links in a new window https://wordpress.org/plugins/open-external-links-in-a-new-window/ which I think would help and template changes.

    I am using the theme Supreme Directory. – I don’t know much about where I would need to change to make this happen and call the Latidude and Longitude cordinates from the WP Database to make this happen. Or if these fixes have been solved to somthing similar I would appreciate the link to help me learn more. Anyone that could help I would be grateful as this would make rock my GeoDirectory world!!

    Thanks in advance.

    #233095

    Kor
    Moderator
    Post count: 16516

    Hi Lee,

    I’ve just spoken with our developer and it’s definitely possible to achieve what you needed there. Could you please insert the function below into the functions.php file? When you’re done, you should be able to see a link “Get Directions on Google Maps” in the details page (Map Tab) and will open a direction in Google Maps when you click on it. Well, give it a try and let us know how it goes.

    
    
    function geodirectory_detail_page_google_map_link( $options, $canvas ) {
        global $post;
        
        if ( $canvas == 'detail_page_map_canvas' && !empty( $post->post_latitude ) && !empty( $post->post_longitude ) ) {
            ?>
            <p><a href="http://maps.google.com/?q=<?php echo $post->post_latitude . ',' . $post->post_longitude ;?>" target="_blank"><?php echo __( 'Get Directions on Google Maps', 'geodirectory' ); ?></a></p>
            <?php
        }
    }
    add_action( 'geodir_map_after_render', 'geodirectory_detail_page_google_map_link', 10, 2 );
    #233911

    Lee Sapara
    Expired Member
    Post count: 7

    Kor Chung Thank you very much and quick response to my issue!! I can’t wait to give this a try!

    #233913

    Lee Sapara
    Expired Member
    Post count: 7

    Hi Kor Chung!! It worked awesome thanks for showing me how to call those Lat’s and Longs and solved my problem 😀 I am still pretty green in WordPress but I am sure this will sink in for me and help me make the customization’s I need. Thanks Again for your time and effort!! Much Appreciated.

    Have a Great Week!!

    #234187

    justmark
    Full Member
    Post count: 375

    Will this be integrated into GD core?

    #234205

    Paolo
    Site Admin
    Post count: 31206

    Not unless it is requested by a lot of members… especially because a solution that can be easily applied was provided here.

    Thanks

    #234294

    justmark
    Full Member
    Post count: 375

    Hi Paolo,

    Could you add this to the “Tips and Tricks” section?

    #235071

    VT
    Full Member
    Post count: 65

    Excellent! We have been looking for this since we have started using your plugin.

    Quick question, can we get a slightly different code that includes the place name too? As is, the link goes to an “Unnamed Place”. From what I understand, a link can be built in the following format:
    http://maps.google.com/?q=%5BThePlace%5D&sll=%5Blatitude%5D,%5Blongitude%5D

    So, something similar to:
    http://maps.google.com/?q=Blackbird+Pizzeria&sll=39.9427098,-75.15201539999998

    Rather than just:
    https://www.google.com/maps?q=39.9427098,-75.15201539999998

    Also, we would like this link to appear on the Profile tab rather than the Map tab. How can we target the profile tab?

    Thanks again, this is Awesome!

    #235083

    Giri
    Expired Member
    Post count: 3155

    Try this code. I have tested it and it works. If you face any problem let me know.

    
    
    function geodirectory_detail_page_google_map_link( $options, $canvas ) {
        global $post;
    
        if ( $canvas == 'detail_page_map_canvas' && !empty( $post->post_latitude ) && !empty( $post->post_longitude ) ) {
            $maps_url = add_query_arg( array(
                            'q' => get_the_title(),
                            'sll' => $post->post_latitude . ',' . $post->post_longitude,
                        ), 'http://maps.google.com/' );
            ?>
            <p><a href="<?php echo $maps_url; ?>" target="_blank"><?php echo __( 'Get Directions on Google Maps', 'geodirectory' ); ?></a></p>
            <?php
        }
    }
    add_action( 'geodir_map_after_render', 'geodirectory_detail_page_google_map_link', 10, 2 );
    #235088

    Paolo
    Site Admin
    Post count: 31206

    I’ll add that moving this into the profile tab is much more complex and that I’m sorry, but it goes beyond support.

    Thanks

    #235098

    Giri
    Expired Member
    Post count: 3155

    Hi there, we have hook in profile page and paolo didn’t know that.

    You can use this code and it would work

    
    
    
    function geodirectory_detail_page_google_map_link() {
        global $post, $preview;
    
        if ( !$preview && !empty( $post->post_latitude ) && !empty( $post->post_longitude ) ) {
            $maps_url = add_query_arg( array(
                            'q' => get_the_title(),
                            'sll' => $post->post_latitude . ',' . $post->post_longitude,
                        ), 'http://maps.google.com/' );
            ?>
            <p><a href="<?php echo $maps_url; ?>" target="_blank"><?php echo __( 'Get Directions on Google Maps', 'geodirectory' ); ?></a></p>
            <?php
        }
    }
    add_action( 'geodir_after_description_on_listing_detail', 'geodirectory_detail_page_google_map_link');

    Thanks

    #235101

    Giri
    Expired Member
    Post count: 3155

    Just FYI,

    If you would like to move the link to the top, replace the string

    geodir_after_description_on_listing_detail

    with

    geodir_before_description_on_listing_detail
    #235113

    VT
    Full Member
    Post count: 65

    Amazing; this is just perfect.

    Thank you! 🙂

    #235836

    Guust
    Moderator
    Post count: 29970

    Hi all, the above info is now added to the documentation:
    https://wpgeodirectory.com/docs/linking-to-google-maps-from-a-detail-page/

    #236165

    Paolo
    Site Admin
    Post count: 31206

    Thanks Guust! 🙂

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