Separate query selections for multiple post types in one mashup

Home Forums MapPress Support Separate query selections for multiple post types in one mashup

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #10978
    BradSiegfried
    Participant

      Hi Chris,

      I am retyping and resubmitting this. My first attempt seems not to have survived the “Submit” button. Maybe the shortcodes that I referenced caused a problem. This time I will use the HTML editor, use the code tags, and save a copy before clicking Submit.

      I need to show a mashup of both the community policing unit that serves a selected neighborhood and the recent police news releases regarding nearby events. I can display either the unit or the news releases, but not yet both in one map.

      Here’s what I tried:


      [mappress width="300" height="200" zoom="13" overviewmapcontrol="false" maptypecontrol="false" marker_body="none"]

      [mashup query="post_type=units,post&category_name=wpd-news-release&posts_per_page=10&meta_key=address&meta_value!=_wp_zero_value" show="current" width="300" height="200" zoom="13" overviewmapcontrol="false" maptypecontrol="false" marker_body="none" marker_link="true" marker_title="post" iconid="iimm1-blue" poilist="false" center_lat="[types field="lat" class="" style=""][/types]" center_lng="[types field="lng" class="" style=""][/types]"]

      (Don't worry about the [types] shortcodes, I use those to get the lat and lng values for the mashup map center. They work fine.)

      You can see the results at http://dev-wilmington.crimeboard.org/units/182f/.

      The [mappress] shortcode shows the current unit. The [mashup] shortcode shows the news releases, but not unfortunately the unit. This is probably because there are more than 10 news releases with more recent post dates than the desired unit.

      It seems I need to separate the queries by post type so as to make the mashup query select (post_type=units&show=”current”) AND (“post_type=post&category_name=wpd-news-release&posts_per_page=10&meta_key=address&meta_value!=_wp_zero_value”)

      Even if I limit news releases to 10, they may be in areas not visible on the displayed map. Any news on proximity selection being developed? Or other thoughts on how to approach this?

      Thanks for any suggestions or pointers.

      Brad

      #10979
      Chris
      Keymaster

        Hi Brad,

        If I understood, you’re trying to limit the news releases to 10 but *always* show the unit?

        If so, I don’t think that’s possible because WP allows only one “posts_per_page” for the whole query.  You could set “posts_per_page=-1” and get ALL news, which may not be what you want.

        Or you could take a look at the WP_Query “orderby” clause.  Maybe there’s a way you could order the query so the unit always appears first?  I think the database will read and sort the results be limiting them to 10:

        http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

         

        Finally, you could resort to using PHP to generate the mashup.  Then you can build the POIs based on your news query and add the unit at to the beginning of the POIs array.

        And yes, I’m still working on proximity search – although it might have the same problem if there are > 10 news items in the vicinity.

        #10980
        BradSiegfried
        Participant

          Thanks for the quick response, Chris.  I’ll experiment with the orderby.  At worst case that should let me get all units and all news, then just leave the zoom level to filter the view.

          It sounds like PHP will be the best option in the long run.  If I were to use PHP to build the mashup, would I do separate queries, one for units and one for news, then concatenate the results?  I looked through http://mappresspro.com/mappress-documentation#toc-mashups but didn’t see an example of building a mashup with PHP.  Could you link me to some reading material on this?

          Great news on the proximity search.  I’m hoping that once I get the PHP option mashup working, the proximity search will drop in there nicely.

          Thanks for your help.

          Brad

          PS. I think my earlier submission problem was that I failed to enter a title when I first submitted.

          #10981
          Chris
          Keymaster

            Hi Brad,

            There’s no example of building a mashup, since if you’re using PHP you can just create a map (you don’t need a query).

            There’s an example of creating two POIs and displaying them together on a map, so that’s what you’d need to extend:

            1) Read the unit post and create a POI for it

            2) Query the news posts and create POIs for each one

            3) Combine the two sets of POIs into one array and display the map

            Here’s an example of how to get all the POIs for an array of WordPress posts ($posts):

            $pois = array();   
            foreach($posts as $post) {        
              // Get the maps for each post    
              $maps = Mappress_Map::get_post_map_list($post->ID);
            
              // Add the pois for each map    
              foreach($maps as $map) {     
                foreach ($map->pois as $poi) {         
                  $poi->postid = $post->ID;      
                  $pois[] = $poi;     
                }    
              }   
            }
            #10982
            BradSiegfried
            Participant

              Thanks, Chris.  I’ll work on that.

              #11005
              BradSiegfried
              Participant

                Hi Chris,

                I have this almost working.  However, the resulting map center seems not to be as specified in the code.  If I manually move the displayed map, I can see my POIs, but the initial map center appears to be around 5 miles south of the desired coordinates, resulting in 39.601191,-75.605221 instead of the requested 39.749031, -75.57013.  There are no POIs in view on the initial map display.

                You can see the results at http://dev-wilmington.crimeboard.org/units/182f/.

                Code snippet:

                function cbquerymap($atts, $content = null) {
                global $cbdatefrom, $cbdateto;
                extract( shortcode_atts( array(
                ‘cbdatefrom’ => date(‘Y-m-d’, strtotime(‘-30 days’)),
                ‘cbdateto’ => date(‘Y-m-d’),
                ‘cblat’=>”39.749031″,
                ‘cblng’=>”-75.57013″,
                ), $atts ) );
                $result = “”;

                … more code happens …

                // Return the map display;
                $mymap = new Mappress_Map(array(“width” => 300, “height” => 200, “zoom” => 13, “posts_per_page”=> -1, “overviewmapcontrol” => false, “maptypecontrol” =>false, “marker_body” => “none”, “marker_link” => true, “marker_title” => “post”, “poilist” => false, “center_lat” => $cblat, “center_lng” => $cblng));
                $mymap->pois = $pois;
                $result = $mymap->display();

                $result .= “lat= $cblat, lng= $cblng”;
                return ($result);

                I see that there is one outlier POI much farther south than the rest.  It appears that the map center is being calculated rather than taken from the “center_lat” and “center_lng” values I specified.  Can you point me toward a solution?  Your login credentials are the same as before at http://dev-wilmington.crimeboard.org if you want to take a closer look.  See the “xper” plugin.

                Thanks.

                Brad

                #11007
                BradSiegfried
                Participant

                  Found it at http://mappresspro.com/mappress-beta#toc-settings.

                  Changed to the required “center” array format instead of “center_lat” and “center_lng”:

                  $mymap = new Mappress_Map(array(“width” => 300, “height” => 200, “zoom” => 13, “posts_per_page”=> -1, “overviewmapcontrol” => false, “maptypecontrol” =>false, “marker_body” => “none”, “marker_link” => true, “marker_title” => “post”, “poilist” => false, “center” => array(“lat” => $cblat, “lng” => $cblng)));

                  It works!

                  #11042
                  BradSiegfried
                  Participant

                    Hi Chris,

                    I am calculating distance of each POI from the map center and would like to append that information to the Location that is shown in the poilist.  I also plan to use that value to filter results.  Can you tell me which object or array value I need to update in reference to your code sample above (#10981)?

                    Also, is it possible to exclude some points from the poilist but leave them in the map display?

                    See http://sgowtham.net/blog/2009/08/04/php-calculating-distance-between-two-locations-given-their-gps-coordinates/ for the distance calculation that I’m using.

                    Thanks.

                    Brad

                    #11045
                    BradSiegfried
                    Participant

                      An example of maps with poilist sorted by proximity to map center is at http://dev-wilmington.crimeboard.org/units/. The tooltip on the map does show the distance from the map center, but I’d like to show that in the poilist as well.
                      $poi->title = “($slc_distance miles) $poi->title”;
                      The above code does not change the poilist display as I thought it would, just the tooltip on the map.

                       

                      #11106
                      BradSiegfried
                      Participant

                        I updated to MapPress 2.39.0.  The poilist now displays as I wanted it to.

                      Viewing 10 posts - 1 through 10 (of 10 total)
                      • You must be logged in to reply to this topic.