Open naturalfusion opened 5 years ago
@andywalz Can probably assist you with this.
@naturalfusion If a global search is what you desire then you shouldn't need to use ST_INTERSECTS at all, you should be able to just leave out the meta_query and still use distance for sorting.
Although coordinates are longitude/latitude, in MySQL it is assumed that they are planar. This will lead to errors/inaccuracies when considering large areas (like your buffered point with really large radius) or working on areas near the poles. You can read more about this here.
First off, absolutely great plugin, Well done. Hopefully, you can help with a problem that I am having.
The goal is to search for photographers from a point(latitude and longitude) and order the results by distance from that center point. The below code works great, however, we are getting limited results. For example, if I do a search from the center point Bangkok Thailand, we are only getting photographers in Asia, and not in North America. The same results happen when doing a search in North America, no Asia photographers. I thought by increasing the mile radius (some large number like 24,901 miles) would solve this problem, but it results in no results. So the goal is to do a global search. Am I missing something? Thanks!
CODE USED
WP_GeoUtil::wp_buffer_point_mi($center_point,10000,8); $results = new WP_Query( array( 'post_type'=> 'photographer', 'orderby' => 'distance', 'order' => 'ASC', 'meta_query' => array( 'inbuffer' => array( 'key' => 'location', 'compare' => 'ST_INTERSECTS', 'value' => $buffered_shape ), 'distance' => array( 'key' => 'location', 'compare' => 'ST_DISTANCE', 'value' => $center_point, 'type' => 'DECIMAL(10,7)' ) ),
));