AyeCode / geodirectory

GeoDirectory is the leading Directory Plugin for WordPress. Compatible with Gutenberg and the most popular page builders such as Elementor, Oxygen, Beaver Builder and Divi. GeoDirectory is the only solution for WordPress that can scale to millions of listings and high traffic.
https://wpgeodirectory.com/
Other
41 stars 22 forks source link

Geocoding API key - http referrer settings block access to geocoding api #826

Closed alexrollin closed 3 years ago

alexrollin commented 5 years ago

A member has reported and the team has confirmed that a a google api key with http referrer settings cannot access the geocoding API.

This necessitates some change to allow for a second key that does not have http referrer settings specifically for 'hidden' geocoding operations (that won't expose the unrestricted api key).

https://wpgeodirectory.com/support/topic/geocoding-importing-and-google-maps-api-restrictions/#post-493432

Of note, many members have also requested the ability to use google for geocoding but using OSM for viewing maps. They want accurate addresses and lat lon but don't want to pay simply for map views.

alexrollin commented 5 years ago

Is it possible to allow Google for Geocoding even if OSM is selected as the Maps API?

kprajapatii commented 5 years ago

Added new hook to filter API used to get address from GPS. https://github.com/AyeCode/geodirectory/commit/89b9d7ea96686a5f389ee04b6cdfc25ea5210b33#diff-5147394367773dee85450faa4945b20aR219

Here examples:

/**
 * Filter Geocode API used to get GPS from post address.
 */
function gd_snippet_post_gps_from_address_api( $api ) {geodir_error_log( $api, 'gd_snippet_post_gps_from_address_api', __FILE__, __LINE__ );
    $api = 'google'; // google or osm

    return $api;
}
add_filter( 'geodir_post_gps_from_address_api', 'gd_snippet_post_gps_from_address_api', 20, 1 );

/**
 * Filter Geocode API used to get address from post GPS.
 */
function gd_snippet_post_address_from_gps_api( $api ) {geodir_error_log( $api, 'gd_snippet_post_address_from_gps_api', __FILE__, __LINE__ );
    $api = 'google'; // google or osm

    return $api;
}
add_filter( 'geodir_post_address_from_gps_api', 'gd_snippet_post_address_from_gps_api', 20, 1 );

Above PHP snippets will force to use specific API to get GPS from address & to get address from GPS during import listing & insert dummy data.

alexrollin commented 5 years ago

Add listing page https://github.com/AyeCode/geodirectory/blob/2e4d5a382f1e2e9d399ebbdfd321de8fdcf84fa3/includes/class-geodir-maps.php#L53

/**
 * Load Google map on add listing page.
 */
function gd_snippet_map_name( $map ) {
    if ( geodir_is_page( 'add-listing' ) ) {
        $map = 'google'; // google or osm
    }
​
    return $map;
}
add_filter( 'geodir_map_name', 'gd_snippet_map_name', 20, 1 );