Forums › Feature Requests › Show a get directions link in post
Tagged: get directions link
- This topic has 13 replies, 3 voices, and was last updated 4 years, 1 month ago by
alim.
-
AuthorPosts
-
September 8, 2015 at 2:20 pm #44084
Joseph Barrett
MemberI need to add a get directions link that functions the same as in the search results. The gmw_single_location shortcode has a get directions link but asks for the current address when clicked. I would like the link to just open google maps in a new page as it is clicked and populate “your location” as the from locaion. Just like on the search results . Does that make sense?
Thank You Sir!
September 27, 2015 at 7:48 pm #45499Eyal Fitoussi
MemberHi Joseph,
It does make sense. I am now working on the next major update of GEO my WP and I will be adding new shortcakes and functions. I will look into adding this feature as well.
September 28, 2015 at 4:31 am #45528Joseph Barrett
MemberI don’t really need a shortcode for it, but I can’t write up the correct php to generate the right url. For example, I have no idea how to call that post’s lng+lat in to a google URL.
http://maps.google.com/maps?saddr=&daddr=PostCoordinatesGoHere
I just don’t know how to get pull the address or coordinates from the post location and put it in the link in the template. What would you suggest?September 29, 2015 at 9:48 pm #45679Eyal Fitoussi
MemberIf you are going to place the directions link via PHP ( in a template file ) then you can use the function gmw_get_post_location_from_db( $post_id ) the get the post’s location.
So you can do something like:123456$location = gmw_get_post_location_from_db( $post_id );if ( ! empty( $location ) ) {$lat = $location->lat;$long = $location->long;}Does this help?
September 30, 2015 at 4:13 am #45690Joseph Barrett
MemberABSOLUTELY! I was missing the from_db.I’ll try this today. Thanks Sir!
September 30, 2015 at 2:47 pm #45717Joseph Barrett
MemberYeaaaaa, i cant get it to write the coords in to the link… i am NOT a php developer thats for sure
September 30, 2015 at 10:41 pm #45727Eyal Fitoussi
MemberTry this:
12345678910$latLng = '';$location = gmw_get_post_location_from_db( $post_id );if ( ! empty( $location ) ) {$latLng = $location->lat.','.$location->long;}$directions_link = '<a href="http://maps.google.com/maps?saddr=&daddr='.$latLng.'" rel="nofollow">Get directions</a>';echo $directions_link;September 30, 2015 at 10:45 pm #45728Eyal Fitoussi
MemberMake sure to replace & with & in the directions link. The code got a bit messed up.
October 1, 2015 at 8:10 am #45754Joseph Barrett
Membernah, it renders the link but the $latlng is still empty in the href. I just slapped some <?php ?> around your code though in the post template. I will continue to mess around with it. Thanks man.
I can use shortcodes to do this, which is ok, and now I feel i HAVE to make it work without using shortcodes LOL
<a href="http://maps.google.com/maps?saddr=&daddr=<?php echo do_shortcode('[gmw_post_info info="lat"]'); ?>,<?php echo do_shortcode('[gmw_post_info info="long"]'); ?>" target="_blank" >Get Directions</a>
October 1, 2015 at 11:54 pm #45794Eyal Fitoussi
MemberAre you sure the $post_id you are passing is correct?
Usually to get the post ID in a single template file you need to do
12global $post;$post_id = $post->IDOctober 6, 2015 at 5:07 am #45998Joseph Barrett
MemberThat did it I know even less about wp than i know about php! you are a great teacher i really appreciate your time and help!
November 8, 2015 at 9:58 am #48795Eyal Fitoussi
MemberYou are welcome Joseph. I am glad I could help.
April 7, 2018 at 6:57 am #57109alim
MemberHellow sir eyal .
ihave same question to but , it from difrent activity.
how can i delcare the get drection link to status user from buddypress gmw ?.
I know the function already exists, but it’s just declare href for the country code and location name, how to convert it to lat,long code? ,
thanks before sir ,April 7, 2018 at 6:59 am #57110alim
MemberThis reply has been marked as private. -
AuthorPosts
You must be logged in to reply to this topic.