{"id":915,"date":"2025-03-24T14:28:01","date_gmt":"2025-03-24T14:28:01","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/use-google-for-geocoding-and-openstreetmaps-for-map-displays\/"},"modified":"2025-04-03T15:24:21","modified_gmt":"2025-04-03T14:24:21","slug":"use-google-for-geocoding-and-openstreetmaps-for-map-displays","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/use-google-for-geocoding-and-openstreetmaps-for-map-displays\/","title":{"rendered":"Use Google for GeoCoding and OpenStreetMaps for map displays"},"content":{"rendered":"\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">Use <strong>OpenSteetMaps for frontend<\/strong> map displays<br>Use <strong>Google Maps to add addresses<\/strong> to your database<\/span><\/div>\n\n\n\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-success mb-3\" role=\"alert\"><span class=\"fas fa-check-circle me-2\"><\/span><span class=\"flex-grow-1\">Read more about <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/how-tos\/differences-between-the-google-maps-and-openstreetmap-apis\/\">Differences between the Google Maps and OpenStreetMap APIs<\/a>.<\/span><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Map settings<\/h2>\n\n\n\n<p>Go to <strong>GeoDirectory &gt; Settings &gt; General tab &gt; General sub-tab &gt; Show Advanced<\/strong> and add your Google APi keys, and set the Maps API to use OpenStreetMaps. <img loading=\"lazy\" decoding=\"async\" class=\"attachment-large size-large\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-gzrPwMKPiP.png\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" srcset=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-gzrPwMKPiP.png 784w, https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-gzrPwMKPiP-300x100.png 300w, https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-gzrPwMKPiP-768x256.png 768w\" alt=\"\" width=\"784\" height=\"261\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add PHP code<\/h2>\n\n\n\n<p>Add the following <strong> PHP code<\/strong> (we recommend using the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippets plugin<\/a>)<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">\/**\n * Load Google map on admin backend add or edit listing page.\n *\/\nfunction gd_snippet_admin_add_listing_map_name( $map ) {\n    global $post, $pagenow;\n    if( ( &#039;edit.php&#039; === $pagenow || &#039;post.php&#039; === $pagenow || &#039;post-new.php&#039; == $pagenow ) &amp;&amp; ! empty( $post-&gt;post_type ) &amp;&amp; geodir_is_gd_post_type( $post-&gt;post_type ) ) {\n        $map = &#039;google&#039;; \/\/ google or osm\n    }\n    return $map;\n}\nadd_filter( &#039;geodir_map_name&#039;, &#039;gd_snippet_admin_add_listing_map_name&#039;, 20, 1 );\n\/**\n * Load Google map on frontend add or edit listing page.\n *\/\nfunction gd_snippet_map_name( $map ) {\n    if ( geodir_is_page( &#039;add-listing&#039; ) ) {\n        $map = &#039;google&#039;; \/\/ google or osm\n    }\n    return $map;\n}\nadd_filter( &#039;geodir_map_name&#039;, &#039;gd_snippet_map_name&#039;, 20, 1 );\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Map settings Go to GeoDirectory &gt; Settings &gt; General tab &gt; General sub-tab &gt; Show Advanced and add your Google APi keys, and set the Maps API to use OpenStreetMaps. Add PHP code Add the following PHP code (we recommend using the Code Snippets plugin)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[753],"article\/categories":[432,211,433],"class_list":["post-915","gd_place","type-gd_place","status-publish","hentry","gd_place_tags-osm","gd_placecategory-how-tos","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=915"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/915\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=915"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=915"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}