Join our new community forum for support & discussionJoin Now
Home › Support › Extensions › Geolocation › Restrict regions to cities only
Restrict regions to cities only
I’ve noticed the new update, interesting approach 🙂
I was thinking that will act like as second taxonomy for listings, same settings/display as categories.
I’m testing it locally with GMaps and first conclusions are:
– adding regions manually in backend has no impact on frontend, the regions created cannot be selected on add/edit listing
– my first thought was that it will be created a region for every street that vendor is adding to its listing 🙂
– maybe a new block for displaying regions will be nice
– maybe a new block for displaying listings based on category & regions will be nice
But the big question is how to restrict it to only some cities, right now it creates a structure like this:
Country -> County -> City municipality -> City (same) (at least for my country, screenshot)
Ah, the Mapbox creates a simplier structure Country -> County – > City.
Good work however, I hope it will be an option to restrict geolocation somehow to only cities of one county for local niches’ websites.
Thanks !ihor 11 months, 4 weeks ago developer
Thanks for your feedback,
Yes, regions are managed automatically (based on region IDs returned by the maps API), the city being the most detailed one. For USA, the following levels are generated: country, state, county, city/town. The county level is required because towns can have the same name, but different counties within the same state. A similar structure is used for other countries (up to 4 levels).
We plan to add the same front-end features as for categories (a block, page header, etc) so it will be possible display the region title & description for SEO. Also we’ll check if it’s possible to add some option for managing the region levels, but using a single level of cities may not be possible since there can be cities/towns with the same name.
I understand your point and I have read something about gmaps strictbounds & types, the problem is that we leave the option to regular users for adding whatever location they want, by mistake or same city but in wrong state, it will create unnecesary locations, a restriction on state/county level will be a good option I think.
Yes, I was thinking about some option to restrict levels (e.g. to cities only if the site owner is sure that these will not conflict). Also, maybe a recurring function to clear empty regions (to prevent flooding the DB with regions of the deleted listings or changed locations).gabetu 11 months, 3 weeks ago
Commenting these lines in class-geolocation.php creates only city level regions:
$request_url = 'https://maps.googleapis.com/maps/api/geocode/json?' . http_build_query( [ 'latlng' => $latitude . ',' . $longitude, 'key' => get_option( 'hp_gmaps_api_key' ), 'language' => hivepress()->translator->get_language(), 'result_type' => implode( '|', [ 'locality', //'administrative_area_level_2', //'administrative_area_level_1', //'country', ] ), ] );
I think that adding
if conditionfor options like “Create country level ?”, Create (province) administrative area level_1 ?” and “Create (state) administrative area level_2 ?” will be very useful, people don’t know yet but they will ask for 🙂
As for restricting geocode to state/city only it seems that is a little bit tricky, there are several methods around
strictBounds: true, creating a new latlong bounds constant, using
location: 'lat, long'and
radius: 'xxx'or using some predictions.
Here is a modified & unminified code of
jquery.geocomplete.min.jsthat works quite ok, around 90% precision.
Thanks for sharing, we’ll consider adding a multiple selection setting for managing region levels.
This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.