Mapping Addresses

WP Issues CRM supports the presentation any list of found constituents on maps. You can add layers (like district boundaries) that will be displayed on all maps. If political party is coded, found constituents will show as red, blue or purple.

There are three parts to making this work.

First, all presentation of maps relies entirely on the Google Maps API — so an API Key needs to installed, following the instructions on your WP Issues CRM Main Settings geocoding tab.

Second, although the Google Maps API can do geocoding, it is not designed to support real time geocoding of a large number of points, so we need to geocode all the addresses in advance to be ready for presentation. One economical service that does geocoding is Gecodio. If you get yourself a Geocodio API key and install it in main settings, WP Issues CRM will do the rest.

Please note that the geocoding process handles batches of 10,000 addresses every five minutes, so that if you add 120,000 records to your database, it will take approximately an hour to geocode them all.

If you are running multi site, you can install either or both the Google Maps and Geocodio keys in your wp-config.php and they will be available to all sites on your installation. Just plug your keys into these two lines and add them to wp-config.php somewhere above “/* That’s all, stop editing! Happy blogging. */”:

define( 'WIC_GOOGLE_MAPS_API_KEY', 'YOUR_MAPS_API_KEY');
define( 'WIC_GEOCODIO_API_KEY','YOUR_GEOCODIO_KEY');

If you configure the Geocodio API centrally, then all sites will share looked up addresses, saving costs — once an address has been geocoded by one site, it will be saved in a central cache for others to use.

Especially in a central installation, it may make sense to install a cron tab to assure that geocoding continues while the site is idle. Place the following line in your wp-config.php:

define( 'WIC_GEOCODING_CRON_RUN_KEY', 'some_long_string_letters_and_numbers');

And then set up a cron tab through CPanel to run every five minutes:

wget -q -O - http://yoursiteurl/?wic_geocoding_cron_run_key='the_same_long_random_string'

The results of geocoding runs can be monitored in the file named wp_issues_crm_geocoding_log which will appear in the wp-content directory.

You can also write your own geocoding function to user your preferred geocoding data source instead of Geocodio. Just name it wp_wic_lookup_geocodes_local and install it as a WordPress plugin and WP Issues CRM will turn to that function. Refer to the code for WIC_Entity_Geocode::update_geocode_address_cache as a model.

Finally, to add layers, you must encode them in geojson format and then point to them in the wp-config.php file by carefully following this example:

define('WP_ISSUES_CRM_MAP_DATA_LAYERS',
array (
array( 'layerTitle' => 'Senate Districts', 'layerURL' => 'http://localhost/senatedistricts.geojson'),
array( 'layerTitle' => 'House Districts', 'layerURL' => 'http://localhost/repdistricts.geojson'),
array( 'layerTitle' => 'Municipalities', 'layerURL' => 'http://localhost/town351.geojson'),
)
);

Leave a comment

Your email address will not be published. Required fields are marked *