woocommerce 中的地理围栏产品

Geofencing products in woocommerce

我正在使用 Wordpress 和 Woocommerce 开发一个小型本地配送网站。我正在尝试实现一个条件字段或代码的一部分,将地理围栏(可能不是正确的术语)产品与其邮政编码。例如,输入特定邮政编码半径的人只能查看他们所在地区的精选产品。看来我正在寻找一种 SauceyApp.com 或 Just-Eat.co.uk 类型的搜索功能。我假设这需要使用某种形式的 Google 地图插件。我已经搜索了数周,甚至无法深入了解从哪里开始。我想知道是否有人知道我该怎么做,或者对从哪里开始有一个模糊的想法?

Google 地图有一个 Places API where you can put in a location and radius and get an autocomplete for searching local places and lists of places to map by category. To get a users location you could use the Geolocation Api which is supported by most browsers (IE 9+) or a geolocation service. All that's required is an Api key from google, location, and radius. They you can send in options to filter the data. Information on these parameters is listed here in googles docs

示例查询如下所示:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&rankby=distance&types=food&key=YOUR_API_KEY

有几个围绕这个 api 的开源包装器可以让你开始:

python-google-places

google-places-api-java

Ruby wrapper for Google Places