Support Forum
Support › Meta Box Geolocation › Filter by distanceResolved
Hello
How do I:
1 ) have a front end google api field that gives me latitude and longidute
2 ) how do I filter my wp query by distance from the location indicated in the field on question 1?
case use:
My client has some houses and each house has an address.
visitor insert a city and the wp query filters the results and shows only the houses near that city (the distance is not important now, lets say 50km)
Hi,
The extension Meta Box Geolocation helps you enter an address then it will autosuggest a complete address and fill all other fields. In your case, I think you need to calculate the distance first, find the house (post) that has the shortest distance then show it on the map.
Links below will help you to achieve your goal.
https://stackoverflow.com/questions/29003118/get-driving-distance-between-two-points-using-google-maps-api
https://metabox.io/display-all-listings-on-a-map/
I am sorry but how can I use the geolocation extension on the front end? I successfully installed on the backend but how can I add a text field that autopopolate latitude and longitude fields with google API on the front end?
thank you in advance, always really helpful and fast
Hi,
You can use the extension MB Frontend Submission to use fields and extensions on the frontend. For more information, please follow this documentation https://docs.metabox.io/extensions/mb-frontend-submission/.
Ok thanks,
The front end form shows all the fields, in order to show only the address field is there a clean way to hide the others or I have to use css/javascript?
Ok i succeded by:
1) creating an input with autocomplete with
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
2) taking some of the code and ideas from
https://stevepolito.design/blog/create-a-proximity-search-in-wordpress/
have a nice day!