State and country wise location filter (using Geolocation plugin)

Hello, I have just installed the Geolocation plugin (and maps api key as per Hivepress instructions) to enable user location input and filtering listings by location. The filter only seems to be working on a city wide basis. I have added test listings which have their location set within a city (Mumbai, Maharashtra, India). So when I search for Mumbai in my location search filter, it displays the listings from the city but when set the filter to a state wide filter (Maharashtra, India), it says “nothing found”. Same result when I search with location filter as “India”.

What can I do here? I hope my explanation is clear. If you want to visit my website, here’s the link:
https://fixpaana.in/

Please make sure that regions are generated for this location (if you add a new listing or change the location for the existing one) and enabled Regions in HivePress/Settings/Listings/Geolocation section. Then search by regions (country, state, county, city) should work fine

What do you mean by:

When I input the location for the listing, it does get selected in the “city, state, country” format. If that’s what you mean, I have ensured that. And I have enabled Regions “Generate regions for locations” also. It’s still giving me the issue.

If Generate regions from locations option is enabled then please check that regions are added to Listings/Regions

I am not sure what to look for. Currently, under Listings/Regions, there is nothing added. Is it supposed to auto populate? What should I do?

Regions are generated automatically if you use the correct key for the chosen map provider (Mapbox or Google Maps API) and if Generate regions from locations option is enabled. Please try to re-save some listing and a region will be added to Listings/Regions if these conditions are met. Then search by regions (country, state, county, city) should work fine

I did try. I even tried adding a couple of listings but it is still not working. I have used the GoogleMaps api key and all other features are working fine, just having issue with this filter.

What else am I missing?

If Generate regions from locations is enabled and regions have been added to Listings/Regions after you add, save or re-save some listing, then please check this topic How to assign Region to Listing | HivePress Support as there is also can be a problem with Google Maps API

I followed through the post shared. Tried the things mentioned there too but it doesn’t seem to work for me. Regions is enabled and everything else is fine but when I resave or add a new listing, the Regions are not being created in the Listings/Regions.

What else can I try?

Please try these solutions

  1. Please try to remove the HTTP restriction for Google Maps API (as described here How to assign Region to Listing | HivePress Support ). Then if you remove HTTP restrictions please limit API quotas in case someone tries to use your API key on their website. Then please try to edit/add a location for some listing and save it. Then please check if this location has been added to Listings/Regions.

  2. Please try to use Mapbox

Thank you! I tried MapBox and it worked well. No problems now. However, I has a “public token” does that mean it doesnt need to be restricted to my website?

Yes, the public token does not seem to require any restrictions, but it has a free limit if the billing is not enabled (it should be enough even for decent traffic though).

I am facing an issue here. Although Mapbox works well, I don’t like the way it classifies region hierarchy. For eg. I have 2 listings with location as “XYZ, Mumbai, Maharashtra, India” (xyz being the exact location address). One of the address I have added is in the heart of the city and the other is in the suburb. For the address in the city, when I add a listing, the regions added are “Maharashtra, Mumbai City, Mumbai” (parent, child, child2) while for the other location in the suburb its “Maharashtra, Mumbai Suburban, Mumbai” (parent, child, child2).

The problem with this is that when the user searches for listings in Mumbai, Maharashtra, India only the listings with the region hierarchy “Mumbai, Mumbai suburban, Maharashtra” are displayed and not the ones that are “Mumbai, Mumbai City, Maharashtra”. Ideally they all should be displayed as the location for all is the same: Mumbai.

FYI: when I add the location for a listing as “Mumbai, Maharastra, India” the regions added are “Mumbai, Mumbai suburban, Maharashtra” (parent, child, child2). And that’s why the “Mumbai, MH, IND” filter is not working as a superset I believe.

I hope I was able to explain the issue well. I know that probably this is an issue with Mapbox and not Hivepress but just wanted to know what you guys had to say about that.

Thanks for your feedback. Unfortunately we don’t have control over this, I guess they have some non-precise regions data for India - HivePress just fetches the data provided via the API.

I was not very happy with how Mapbox was performing so was trying to see if I can get Google to work:

Please try to remove the HTTP restriction for Google Maps API (as described here How to assign Region to Listing | HivePress Support ). Then if you remove HTTP restrictions please limit API quotas in case someone tries to use your API key on their website. Then please try to edit/add a location for some listing and save it. Then please check if this location has been added to Listings/Regions.

What do you mean exactly by “removing the HTTP restriction”? Based on my understanding of the Hivepress Support thread I have selected NONE under “Application Restrictions” and under API restrictions I have only restricted Maps JavaScript and Places API while leaving the Geocoding API unrestricted as in the image attached. Is that correct? What else am I missing?

FYI: the problem is that google maps is not generating regions so my location based search filter is not working properly.

Also, what does the “Secret Key” field in Hivepress Integrations settings for Google Maps supposed to be for?

If Regions are required please create 2 API keys for Google Maps by following the linked tutorial (make sure that 3 APIs are enabled for each key: Places, Maps and Geocoding). Then set HTTP restrictions for the first API key (e.g. yoursite.com/* ) to prevent using this key on other sites, and don’t restrict the second key. Then set the first key in the Google Maps section in Integrations, and set the second (non-restricted one) as the Secret Key.

Thanks @yevhen ! Regions with Google maps are now working! After enabling Maps, Geocoding and Places API as needed for the location plugin setup, I created 2 keys, one with “Application restrictions” as “None” and one with appropriate “IP Addresses”. For both keys I used “API Restrictions” for all three APIs, limiting the keys to call only Geocoding, Maps and Places api.

The key with “Application Restrictions” as “None”, was pasted in the Secret Key field in Hivepress settings and the other (IP address restricted) key was used as the normal Google api key.

These settings worked for me, incase anyone else is facing any issues with this.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.