"Get Directions" button to Open Google Maps Link
This topic contains 15 replies, has 7 voices, and was last updated by Lee Sapara 8 years, 7 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
July 23, 2016 at 6:11 pm #232446
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.
July 25, 2016 at 7:04 am #233095Hi 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 );
July 26, 2016 at 11:48 pm #233911Kor Chung Thank you very much and quick response to my issue!! I can’t wait to give this a try!
July 27, 2016 at 12:26 am #233913Hi 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!!
July 27, 2016 at 4:15 pm #234187Will this be integrated into GD core?
July 27, 2016 at 5:20 pm #234205Not unless it is requested by a lot of members… especially because a solution that can be easily applied was provided here.
Thanks
July 27, 2016 at 7:17 pm #234294Hi Paolo,
Could you add this to the “Tips and Tricks” section?
July 28, 2016 at 4:14 pm #235071Excellent! 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%5DSo, something similar to:
http://maps.google.com/?q=Blackbird+Pizzeria&sll=39.9427098,-75.15201539999998Rather than just:
https://www.google.com/maps?q=39.9427098,-75.15201539999998Also, 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!
July 28, 2016 at 4:39 pm #235083Try 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 );
July 28, 2016 at 4:40 pm #235088I’ll add that moving this into the profile tab is much more complex and that I’m sorry, but it goes beyond support.
Thanks
July 28, 2016 at 4:50 pm #235098Hi 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
July 28, 2016 at 4:52 pm #235101Just 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
July 28, 2016 at 5:16 pm #235113Amazing; this is just perfect.
Thank you! 🙂
July 29, 2016 at 12:23 pm #235836Hi all, the above info is now added to the documentation:
https://wpgeodirectory.com/docs/linking-to-google-maps-from-a-detail-page/July 29, 2016 at 5:22 pm #236165Thanks Guust! 🙂
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket