Support » Plugin: Stellar Places » center, multiple locations

  • Resolved jbensonism

    (@jbensonism)


    Hey, great plugin. I have imported roughly 1000 locations now. When using the map shortcode, even when I specify coordinates and zoom, it seems to want to center somewhere in the middle of all the locations. Also, when I go to inspect the page source (chrome), the inspector crashes all the time because the markup for all 1000 locations is in the html.

    I removed the line:
    data-stellar-places-map-locations="<?php echo esc_attr( json_encode( $this->_locations ) ); ?>"

    from get_html, and now my inspector doesn’t crash (and i don’t have places). I’m looking for a way to get the places on the map and not in the dom now. I don’t want to create my own shortcode and js to do this, but I may have to. any help much appreciated.

    https://wordpress.org/plugins/stellar-places/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Micah Wood

    (@woodent)

    @jbensonism,

    I’ve been made aware of the zoom issue. I’m planning to correct this issue with the next release.

    Displaying 1,000 listings on a single map is bound to cause issues. The default /locations/ URL is configured to display the map and a set number of listings at a time.

    Is there a specific use case where you absolutely need to display all 1,000?

    It’s for a find a location page.

    I have a search field that queries a zipdata table against city/state or zip, then a given distance from that I have a loop that gets locations and sorts the array by distance from the queried coordinates. User’s should still be able to find all the locations, unless I can the max zoom to correspond with the search area, but I feel like that kind of breaks the user expectation a little.

    I got it to zoom ok by linking my own version of the map js file in the theme directory. I just set it to not extend the position in mapBounds unless it was inside of my bounding coordinates. I also added an additional chance to set the zoom if it is outside of normal range on the first map idle.

    This plugin is very well written

    Plugin Author Micah Wood

    (@woodent)

    @jbensonism,

    One of my next goals is to create an add-on that handles advanced searches like the one you are setting up. I’d love to get as much feedback as possible from you regarding expected functionality.

    I’m looking to make a single MySQL query that returns the results as well as an additional field called distance, which would be the distance from a central point… typically the user’s automatically detected location. Ideally, you would also be able to set bounding coordinates, or have those inferred by a combination of the user’s location and a set number of miles. Given this feature set, the auto zoom feature wouldn’t be an issue since it would only return a subset of the overall data.

    It sounds like you found a workable solution for the meantime though.

    Thanks for the compliment!

    Here is a list of some stuff I needed and what I found, hope it helps to give you ideas.

    • bulk lat / lng coord lookup
    • i had a spreadsheet with all locations, so i used a formula on google docs to concat the address fields into a url w/ api key to google geocoding api, that way when uploading all lat lng are provided. (it would take to long to search individually)

    • bulk upload locations (w/ extra meta fields)
    • i used wp ultimate csv importer and it was able to map the _stlr_places_ fields using add custom field option.

    • bulk delete, just to be safe.
    • added columns in the all locations admin screen
    • to see some more data and be able filter/sort by location category, state, zipcode (and category to the quick edit and bulk edit)

    • advanced query:
    • -get user lat/lng (geolocate, zipdata db, or google geocode fallbacks)
      -measure bounding box. there’s a lot of GIS nonsense about how to get all the coordinates in a search radius, but this is the fastest i came up with to get the deltas, (although now I see a need to just get nw and sw coords instead for more ease with google).
      -select posts using box coordinates
      `
      // $coords array( [0] => $lat, [1] => $lng );
      function get_bounding_coords( $coords, $dist ) {
      // earth in miles
      $R = 3959;
      //distance in one direction
      $delta = rad2deg($dist/$R);
      $new_coords = array();
      $i = 0;

      foreach($coords as $coord) {
      /* since I’m not worried about 180deg or poles,
      just get the distance in every direction, fast and dirty because it runs before i get the posts */

      // typecast in case
      $coord = $coord*1;
      $new_coords[$i] = $coord – $delta;
      $new_coords[$i+1] = $coord + $delta;
      $i = $i+2;
      }
      return $new_coords;
      }`

      -queries: I wanted one inside of the bounding box in case of a really large number of locations, that way it will get a rough pass of the target locations. I think you shortcode / query will be easy to modify for this once you have the user lat/lng.

      `
      $args = array(
      ‘post_type’ => $post_type,
      ‘post_status’ => ‘publish’,
      ‘suppress_filters’ => false,
      ‘meta_query’ => array(
      ‘relation’ => ‘AND’,
      array(
      ‘key’ => ‘_stlr_places_latitude’,
      ‘value’ => array( $deltas[0], $deltas[1] ),
      ‘type’ => ‘DECIMAL’,
      ‘compare’ => ‘BETWEEN’,
      ),
      array(
      ‘key’ => ‘_stlr_places_longitude’,
      ‘value’ => array( $deltas[2], $deltas[3] ),
      ‘type’ => ‘DECIMAL’,
      ‘compare’ => ‘BETWEEN’,
      ),
      array(
      ‘key’ => ‘_stlr_places_latitude’,
      ‘value’ => ”,
      ‘compare’ => ‘!=’,
      ),
      array(
      ‘key’ => ‘_stlr_places_longitude’,
      ‘value’ => ”,
      ‘compare’ => ‘!=’,
      ),
      ),
      );`

      this was needed to maintain decimal precision during the query because of wp sql typecast

      `
      add_filter(‘get_meta_sql’,’cast_decimal_precision’);
      function cast_decimal_precision( $array ) {
      $array[‘where’] = str_replace(‘DECIMAL’,’DECIMAL(30,15)’,$array[‘where’]);
      return $array;
      }`

      Also, the other query that gets them all is great, but i will be wanting to include the extra meta data in my output, phone numbers, social media links, maybe coupons that are specific to groups of locations.

      then to sort the posts after getting them…

      `
      function distance( $lat1, $lon1, $lat2, $lon2 ) {
      $theta = $lon1 – $lon2;
      $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
      $dist = acos($dist);
      $dist = rad2deg($dist);
      $miles = $dist * 60 * 1.1515;
      $miles = number_format($miles, 2, ‘.’, ‘,’);
      return $miles;
      } `

      and a usort on the returned posts with something like:

      `
      function arraySort($a,$b){
      if($a[‘miles’] > $b[‘miles’]){
      return 1;
      }elseif($a[‘miles’] < $b[‘miles’]){
      return -1;
      }
      return 0;
      } `

      -then loop through the sorted posts to display,

      On the search page, i will have a select box for distance, an input for location, and checkbox categories to match from.

      -i will probably add pagination or maaaybe ajax to update the results and map.

      -to fix the inspector crashing, i added some jquery in my page template to wait until everything is finished and remove all the data- attributes added to the map, works great.

      -i noticed a lot of the features that maps supports are not part of the shortcode, but are listed in the class, like zoomControlOptions

      Sorry for the long post, looking forward to any updates on this cool plugin.

    quick update:

    i had to change the arraySort to $a->miles and $b->miles b/c get posts returns array of post objects.

    the query should have a -1 posts per page as well to return all posts

    the return values from the distance function need typecast to sort

    marking resolved

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘center, multiple locations’ is closed to new replies.