Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Josh Pollock

    (@shelob9)

    Right now, there is no built-in way to do this. I recently did a site using GeoMashup, using custom fields from a custom post type added by Pods for the GeoCoding. That plugin makes it really easy to show GeoLocated posts on a map and lets you change the map based on proximity.

    Plugin Contributor Josh Pollock

    (@shelob9)

    I wrote a short tutorial on how I used GeoMashup with Pods to map related post types. In it is a link to how I updated that map based on proximity using FacetWP:

    https://github.com/pods-framework/pods-code-library/blob/master/tutorial/pods-geomashup.md

    Thread Starter JustBruno

    (@justbruno)

    This is great stuff! Thank you!!!

    Plugin Contributor Josh Pollock

    (@shelob9)

    I’m glad this helped. We don’t have direct support, yet for this sort of thing, but plenty of neat ways to do it. We will likely have address fields with map output in Pods 3.0.

    Thread Starter JustBruno

    (@justbruno)

    Thanks again Josh, I’ve just invested nearly 2 frustrating months with a plugin that I think I will soon abandon and build it the right way with some version of your tutorial. Much appreciated!!

    Plugin Contributor Josh Pollock

    (@shelob9)

    You’re welcome.

    Keep in mind that if you use the Proximity Facet from FacetWP like I did, that requires a separate GeoCoding plugin. If you want, I’ll show you how I synced the two GeoCoding plugins.

    Thread Starter JustBruno

    (@justbruno)

    I would love that! I’m a couple of weeks away from rebooting that project but it would be great to have in my pocket when I get started.

    Plugin Contributor Josh Pollock

    (@shelob9)

    So the issue is that the FacetWP wants the Longitude and Latitude to be in meta fields from this plugin. But that plugin doesn’t have map output, hence GeoMashup. But now we need to do double geocoding, which is dumb and inefficient. So instead, I let GeoMashup do my geocoding using Pods fields, since that worked best with the CSV import that was involved.

    Then I used a post_save filter to copy the longitude and latitude to the fields that FacetWP would be looking in. It’s a little silly but it worked. Here’s the filter I used:

    /**
    	 * Copies goecoding from one plugin to another
    	 *
    	 * @uses pods_api_post_save_pod_item_retailers
    	 *
    	 * @param $pieces
    	 * @param $is_new_item
    	 * @param $id
    	 */
    add_action( 'pods_api_post_save_pod_item_retailers', slug_double_geocode, 10, 3 );
    	function slug_double_geocode( $pieces, $is_new_item, $id ) {
    
    		//check if marty geocoder has our geocoding, if so move on with life
    		if ( ! isset( $meta['martygeocoderlatlng'] ) || empty( $meta['martygeocoderlatlng'] ) ) {
    
    			//get post meta
    			$meta = get_post_meta( $id );
    			//get geo_mashup object
    			$gm_obj = GeoMashupDB::get_object_location( 'post', $id );
    
    			//set the variables we are trying to build to false.
    			$latlng = $address = false;
    
    			//see if geomashup has it and if so get geocoding data from there
    			if ( is_object( $gm_obj ) && isset( $gm_obj->lat ) && isset( $gm_obj->lng ) ) {
    
    				$lat = $gm_obj->lat;
    				$lng = $gm_obj->lng;
    				//put it the way marty geocoder likes it
    				$latlng = '('.$lat.', '.$lng.')';
    
    				//check that we can get address from the Pods fields
    				if (  isset( $meta[ 'store_address' ] ) && isset( $meta[ 'store_state' ] ) ) {
    					$address = $meta['store_address'][0].', '.$meta['store_state'][0];
    				}
    
    				//update our post meta from what we already have, if we can
    				if ( $address && $latlng ) {
    
    					update_post_meta( $id, 'martygeocoderlatlng', $latlng );
    					update_post_meta( $id, 'martygeocoderaddress', $address );
    				}
    			}
    
    		}
    
    	}

    As I said, that’s kind of silly, what I should have done is add a filter for location source to the Proximity Facet.

    Thread Starter JustBruno

    (@justbruno)

    Thanks Josh!!

    Hey Josh, when you say

    “what I should have done is add a filter for location source to the Proximity Facet”

    do you mean using the facetwp_index_row filter as documented here?

    Plugin Contributor Josh Pollock

    (@shelob9)

    Ryan – That’s probably what I mean.

    I’m not trying to be difficult, I just don’t remember and I didn’t keep a copy of the code from the work I did on that project.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘location and proximity’ is closed to new replies.