{"id":22614,"date":"2016-07-28T12:46:21","date_gmt":"2016-07-28T12:46:21","guid":{"rendered":"https:\/\/wpgeodirectory.com\/docs\/?p=22614"},"modified":"2016-07-29T12:29:43","modified_gmt":"2016-07-29T12:29:43","slug":"linking-to-google-maps-from-a-detail-page","status":"publish","type":"post","link":"https:\/\/wpgeodirectory.com\/docs\/linking-to-google-maps-from-a-detail-page\/","title":{"rendered":"Linking to Google Maps from a detail page"},"content":{"rendered":"<ol>\n<li>You can get Google Map directions to the location of a listing from a standard GD detail page.<br \/>\nTo get directions, you enter an address in the address field, and then click <em><strong>Get Directions<\/strong><\/em>:<br \/>\n<img loading=\"lazy\" class=\"greenborder\" src=\"https:\/\/wpgeodirectory.com\/docs\/wp-content\/uploads\/sites\/3\/2016\/07\/tips8.png\" alt=\"\" width=\"264\" height=\"151\" \/><\/li>\n<li>That will give directions on the Google map on the website page:<br \/>\n<img loading=\"lazy\" class=\"greenborder\" src=\"https:\/\/wpgeodirectory.com\/docs\/wp-content\/uploads\/sites\/3\/2016\/07\/tips9.png\" alt=\"\" width=\"198\" height=\"227\" \/><\/li>\n<li>The code snippet below will create a link\u00a0on the detail page, that open Google Maps with the location of the GD listing ready on the map.<\/li>\n<li>On a mobile device you can then use the Google Map App to get directions.\n<p>[php]function geodirectory_detail_page_google_map_link( $options, $canvas ) {<br \/>\n    global $post;<\/p>\n<p>    if ( $canvas == &#8216;detail_page_map_canvas&#8217; &amp;&amp; !empty( $post-&gt;post_latitude ) &amp;&amp; !empty( $post-&gt;post_longitude ) ) {<br \/>\n        ?&gt;<br \/>\n        &lt;p&gt;&lt;a href=&quot;http:\/\/maps.google.com\/?q=&lt;?php echo $post-&gt;post_latitude . &#8216;,&#8217; . $post-&gt;post_longitude ;?&gt;&quot; target=&quot;_blank&quot;&gt;&lt;?php echo __( &#8216;Get Directions on Google Maps&#8217;, &#8216;geodirectory&#8217; ); ?&gt;&lt;\/a&gt;&lt;\/p&gt;<br \/>\n        &lt;?php<br \/>\n    }<br \/>\n}<br \/>\nadd_action( &#8216;geodir_map_after_render&#8217;, &#8216;geodirectory_detail_page_google_map_link&#8217;, 10, 2 );[\/php]<\/p>\n<\/li>\n<\/ol>\n<h4>Changing the position on the page<\/h4>\n<ol>\n<li>The above code will add the link below the map on the detail page.<\/li>\n<li>If you want to add the link in the profile tab, you can use this code:\n<p>[php]function geodirectory_detail_page_google_map_link() {<br \/>\n    global $post, $preview;<\/p>\n<p>    if ( !$preview &amp;&amp; !empty( $post-&gt;post_latitude ) &amp;&amp; !empty( $post-&gt;post_longitude ) ) {<br \/>\n        $maps_url = add_query_arg( array(<br \/>\n                        &#8216;q&#8217; =&gt; $post-&gt;post_latitude . &#8216;,&#8217; . $post-&gt;post_longitude,<br \/>\n                    ), &#8216;http:\/\/maps.google.com\/&#8217; );<br \/>\n        ?&gt;<br \/>\n        &lt;p&gt;&lt;a href=&quot;&lt;?php echo $maps_url; ?&gt;&quot; target=&quot;_blank&quot;&gt;&lt;?php echo __( &#8216;Get Directions on Google Maps&#8217;, &#8216;geodirectory&#8217; ); ?&gt;&lt;\/a&gt;&lt;\/p&gt;<br \/>\n        &lt;?php<br \/>\n    }<br \/>\n}<br \/>\nadd_action( &#8216;geodir_after_description_on_listing_detail&#8217;, &#8216;geodirectory_detail_page_google_map_link&#8217;);[\/php]<\/p>\n<\/li>\n<li>If you would like to move the link to the top, replace the string<br \/>\n<em><strong>geodir_after_description_on_listing_detail<\/strong><\/em><br \/>\nwith<br \/>\n<em><strong>geodir_before_description_on_listing_detail<br \/>\n<img loading=\"lazy\" class=\"alignnone size-full wp-image-22632\" src=\"https:\/\/wpgeodirectory.com\/docs\/wp-content\/uploads\/sites\/3\/2016\/07\/tips10.png\" alt=\"\" width=\"411\" height=\"99\" srcset=\"https:\/\/wpgeodirectory.com\/docs\/wp-content\/uploads\/sites\/3\/2016\/07\/tips10.png 411w, https:\/\/wpgeodirectory.com\/docs\/wp-content\/uploads\/sites\/3\/2016\/07\/tips10-300x72.png 300w\" sizes=\"(max-width: 411px) 100vw, 411px\" \/><br \/>\n<\/strong><\/em><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>You can get Google Map directions to the location of a listing from a standard GD detail page. To get directions, you enter an address in the address field, and then click Get Directions: That will give directions on the Google map on the website page: The code snippet below will create a link\u00a0on the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/wpgeodirectory.com\/docs\/linking-to-google-maps-from-a-detail-page\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Linking to Google Maps from a detail page&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1676,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"amp_validity":null,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/posts\/22614"}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/users\/1676"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/comments?post=22614"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/posts\/22614\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/media?parent=22614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/categories?post=22614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/tags?post=22614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}