SlideShare a Scribd company logo
1 of 33
Working with Geolocation in
WordPress
@brianhogg
http://slideshare.net/bhogg
Overview
@brianhogg WordCamp Buffalo Sep 2013 2
 Why Geolocation
 Capturing the Data
 Using the Data
 Getting Visitor Location
About Brian Hogg
@brianhogg WordCamp Buffalo Sep 2013 3
 Software Engineering & Management
 Started and sold DrawBINGO.com
 Lived in Montréal, England, now Cambridge
(Ontario)
 PHP/JS since 2003
Why Geolocation
@brianhogg WordCamp Buffalo Sep 2013 4
 Events blog
 Recommendations
 Mapping
 Store locations
 … anything with content + latitude/longitude
5@brianhogg WordCamp Buffalo Sep 2013
Capturing the Data
@brianhogg WordCamp Buffalo Sep 2013 6
 “Official” Geolocation plugin
http://wordpress.org/extend/plugins/geolocation/
 WP-Geo
http://wordpress.org/extend/plugins/wp-geo/ (for
custom post types)
 WordPress native apps
 … other plugins / themes
Inserting a latitude and longitude for posts.
Capturing the Data
@brianhogg WordCamp Buffalo Sep 2013 7
Capturing the Data
@brianhogg WordCamp Buffalo Sep 2013 8
Capturing the Data
@brianhogg WordCamp Buffalo Sep 2013 9
Inserts a latitude and longitude for each post in the
post meta data.
http://codex.wordpress.org/Geodata
Capturing the Data
@brianhogg WordCamp Buffalo Sep 2013 10
 Import from CSV
Capturing the Data
@brianhogg WordCamp Buffalo Sep 2013 11
 Translating address string to lat/lon (geocode)
http://maps.googleapis.com/maps/api/geocode/xml?
address=Hamilton+ON&sensor=false
<geometry>
<location>
<lat>43.2500208</lat>
<lng>-79.8660914</lng>
</location>
<location_type>APPROXIMATE</location_type>
</geometry>
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 12
 Simple front-end pop-up
 Using WP_Query (meta_query)
 Hooks to store in separate, indexed table
 Custom feeds
 …
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 13
 Simple front-end pop-up
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 14
 Database query
 Get location of user
 Restrict posts using a “bounding box”
 Ordering by distance from a lat/lon
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 15
 Using WP_Query (meta_query)
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 16
 Bounding box query
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 17
 Using WP_Query
@brianhogg WordCamp Buffalo Sep 2013 18
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 19
 Using WP_Query
@brianhogg WordCamp Buffalo Sep 2013 20
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 21
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN
wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) INNER JOIN
wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id) LEFT JOIN
wp_geo geo ON wp_posts.ID = geo.post_id WHERE 1=1 AND
wp_posts.post_type = 'post' AND (wp_posts.post_status =
'publish' OR wp_posts.post_status = 'private') AND
( (wp_postmeta.meta_key = 'geo_latitude' AND
CAST(wp_postmeta.meta_value AS DECIMAL) BETWEEN '42' AND '43')
AND (mt1.meta_key = 'geo_longitude' AND CAST(mt1.meta_value AS
DECIMAL) BETWEEN '-79.9999' AND '-78') ) GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC LIMIT 0, 15
 Sample WP_Query SQL (bounding box)
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 22
 WP_Query method very inefficient especially with
larger amounts of data
 Separate table can be used with an index,
numeric data format
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 23
 Create a new indexed table in the database
 Create a WP hook to store in the new table
CREATE TABLE IF NOT EXISTS `wp_geo` (
`post_id` bigint(20) unsigned NOT NULL,
`lat` float NOT NULL,
`lon` float NOT NULL,
PRIMARY KEY (`post_id`),
KEY `latlon` (`lat`,`lon`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
@brianhogg WordCamp Buffalo Sep 2013 24
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 25
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 26
 posts_clauses filter
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 27
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 28
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 29
 Custom feeds
 Page templates
 Caching?
Using the Data
@brianhogg WordCamp Buffalo Sep 2013 30
 Create map markers from
one or more JSON based
feeds
Getting Visitor Location
@brianhogg WordCamp Buffalo Sep 2013 31
 IP address (approximate)
 GPS
 Google Maps API
Getting Visitor Location
@brianhogg WordCamp Buffalo Sep 2013 32
 IP address (approximate)
 MaxMind – www.maxmind.com
 HostIP - http://www.hostip.info/use.html
 http://ipinfodb.com/ip_location_api.php
 Javascript request (navigator.geolocation)
@brianhogg WordCamp Buffalo Sep 2013 33
Resources / Contact
brian@bhconsulting.ca
@brianhogg

More Related Content

Similar to Working with Geolocation in Wordpress

Groovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: MinneapolisGroovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: MinneapolisJenn Strater
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLLukas Eder
 
Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Sébastien Deleuze
 
Powerful geographic web framework GeoDjango
Powerful geographic web framework GeoDjangoPowerful geographic web framework GeoDjango
Powerful geographic web framework GeoDjangoOMEGA (@equal_001)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMoshe Kaplan
 
WordPress Tips and Tricks (DFW Meetup)
WordPress Tips and Tricks (DFW Meetup)WordPress Tips and Tricks (DFW Meetup)
WordPress Tips and Tricks (DFW Meetup)Stephanie Leary
 
Economies of Scaling Software
Economies of Scaling SoftwareEconomies of Scaling Software
Economies of Scaling SoftwareJoshua Long
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
WebGL Crash Course
WebGL Crash CourseWebGL Crash Course
WebGL Crash CourseTony Parisi
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + SpringBryan Hsueh
 
Data Binding in Action using MVVM pattern
Data Binding in Action using MVVM patternData Binding in Action using MVVM pattern
Data Binding in Action using MVVM patternFabio Collini
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP formatForest Mars
 
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundGet Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundDataGeekery
 
Leaflet JS (GIS) and Capital MetroRail
Leaflet JS (GIS) and Capital MetroRailLeaflet JS (GIS) and Capital MetroRail
Leaflet JS (GIS) and Capital MetroRailterrafrost2
 
Developing PGTop for Android
Developing PGTop for AndroidDeveloping PGTop for Android
Developing PGTop for AndroidMark Wong
 

Similar to Working with Geolocation in Wordpress (20)

GeoMesa on Spark SQL: Extracting Location Intelligence from Data
GeoMesa on Spark SQL: Extracting Location Intelligence from DataGeoMesa on Spark SQL: Extracting Location Intelligence from Data
GeoMesa on Spark SQL: Extracting Location Intelligence from Data
 
Groovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: MinneapolisGroovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: Minneapolis
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQL
 
Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013
 
Powerful geographic web framework GeoDjango
Powerful geographic web framework GeoDjangoPowerful geographic web framework GeoDjango
Powerful geographic web framework GeoDjango
 
Demystifying The Solid Works Api
Demystifying The Solid Works ApiDemystifying The Solid Works Api
Demystifying The Solid Works Api
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Seti 09
Seti 09Seti 09
Seti 09
 
WordPress Tips and Tricks (DFW Meetup)
WordPress Tips and Tricks (DFW Meetup)WordPress Tips and Tricks (DFW Meetup)
WordPress Tips and Tricks (DFW Meetup)
 
Economies of Scaling Software
Economies of Scaling SoftwareEconomies of Scaling Software
Economies of Scaling Software
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
WebGL Crash Course
WebGL Crash CourseWebGL Crash Course
WebGL Crash Course
 
PPT
PPTPPT
PPT
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
 
Data Binding in Action using MVVM pattern
Data Binding in Action using MVVM patternData Binding in Action using MVVM pattern
Data Binding in Action using MVVM pattern
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP format
 
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaroundGet Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
 
Leaflet JS (GIS) and Capital MetroRail
Leaflet JS (GIS) and Capital MetroRailLeaflet JS (GIS) and Capital MetroRail
Leaflet JS (GIS) and Capital MetroRail
 
Django
DjangoDjango
Django
 
Developing PGTop for Android
Developing PGTop for AndroidDeveloping PGTop for Android
Developing PGTop for Android
 

More from Brian Hogg

Submitting, maintaining and growing a plugin on wp.org
Submitting, maintaining and growing a plugin on wp.orgSubmitting, maintaining and growing a plugin on wp.org
Submitting, maintaining and growing a plugin on wp.orgBrian Hogg
 
Preparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for TranslationPreparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for TranslationBrian Hogg
 
Your WordPress Freelance Business Site
Your WordPress Freelance Business SiteYour WordPress Freelance Business Site
Your WordPress Freelance Business SiteBrian Hogg
 
Things I've Learned About Creating a Premium Plugin
Things I've Learned About Creating a Premium PluginThings I've Learned About Creating a Premium Plugin
Things I've Learned About Creating a Premium PluginBrian Hogg
 
WordPress 4.4 and Upgrading Your Site (without the tears...)
WordPress 4.4 and Upgrading Your Site (without the tears...)WordPress 4.4 and Upgrading Your Site (without the tears...)
WordPress 4.4 and Upgrading Your Site (without the tears...)Brian Hogg
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIBrian Hogg
 
Using Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnBrian Hogg
 
Things I learned about Stress and Imposter Syndrome in Tech
Things I learned about Stress and Imposter Syndrome in TechThings I learned about Stress and Imposter Syndrome in Tech
Things I learned about Stress and Imposter Syndrome in TechBrian Hogg
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentationBrian Hogg
 
Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?Brian Hogg
 
Introduction to test driven development
Introduction to test driven developmentIntroduction to test driven development
Introduction to test driven developmentBrian Hogg
 
Intro to Web Apps using HTML5 and Javascript
Intro to Web Apps using HTML5 and JavascriptIntro to Web Apps using HTML5 and Javascript
Intro to Web Apps using HTML5 and JavascriptBrian Hogg
 

More from Brian Hogg (12)

Submitting, maintaining and growing a plugin on wp.org
Submitting, maintaining and growing a plugin on wp.orgSubmitting, maintaining and growing a plugin on wp.org
Submitting, maintaining and growing a plugin on wp.org
 
Preparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for TranslationPreparing a WordPress Plugin for Translation
Preparing a WordPress Plugin for Translation
 
Your WordPress Freelance Business Site
Your WordPress Freelance Business SiteYour WordPress Freelance Business Site
Your WordPress Freelance Business Site
 
Things I've Learned About Creating a Premium Plugin
Things I've Learned About Creating a Premium PluginThings I've Learned About Creating a Premium Plugin
Things I've Learned About Creating a Premium Plugin
 
WordPress 4.4 and Upgrading Your Site (without the tears...)
WordPress 4.4 and Upgrading Your Site (without the tears...)WordPress 4.4 and Upgrading Your Site (without the tears...)
WordPress 4.4 and Upgrading Your Site (without the tears...)
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
 
Using Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your Own
 
Things I learned about Stress and Imposter Syndrome in Tech
Things I learned about Stress and Imposter Syndrome in TechThings I learned about Stress and Imposter Syndrome in Tech
Things I learned about Stress and Imposter Syndrome in Tech
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
 
Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?
 
Introduction to test driven development
Introduction to test driven developmentIntroduction to test driven development
Introduction to test driven development
 
Intro to Web Apps using HTML5 and Javascript
Intro to Web Apps using HTML5 and JavascriptIntro to Web Apps using HTML5 and Javascript
Intro to Web Apps using HTML5 and Javascript
 

Recently uploaded

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Recently uploaded (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Working with Geolocation in Wordpress

  • 1. Working with Geolocation in WordPress @brianhogg http://slideshare.net/bhogg
  • 2. Overview @brianhogg WordCamp Buffalo Sep 2013 2  Why Geolocation  Capturing the Data  Using the Data  Getting Visitor Location
  • 3. About Brian Hogg @brianhogg WordCamp Buffalo Sep 2013 3  Software Engineering & Management  Started and sold DrawBINGO.com  Lived in Montréal, England, now Cambridge (Ontario)  PHP/JS since 2003
  • 4. Why Geolocation @brianhogg WordCamp Buffalo Sep 2013 4  Events blog  Recommendations  Mapping  Store locations  … anything with content + latitude/longitude
  • 6. Capturing the Data @brianhogg WordCamp Buffalo Sep 2013 6  “Official” Geolocation plugin http://wordpress.org/extend/plugins/geolocation/  WP-Geo http://wordpress.org/extend/plugins/wp-geo/ (for custom post types)  WordPress native apps  … other plugins / themes Inserting a latitude and longitude for posts.
  • 7. Capturing the Data @brianhogg WordCamp Buffalo Sep 2013 7
  • 8. Capturing the Data @brianhogg WordCamp Buffalo Sep 2013 8
  • 9. Capturing the Data @brianhogg WordCamp Buffalo Sep 2013 9 Inserts a latitude and longitude for each post in the post meta data. http://codex.wordpress.org/Geodata
  • 10. Capturing the Data @brianhogg WordCamp Buffalo Sep 2013 10  Import from CSV
  • 11. Capturing the Data @brianhogg WordCamp Buffalo Sep 2013 11  Translating address string to lat/lon (geocode) http://maps.googleapis.com/maps/api/geocode/xml? address=Hamilton+ON&sensor=false <geometry> <location> <lat>43.2500208</lat> <lng>-79.8660914</lng> </location> <location_type>APPROXIMATE</location_type> </geometry>
  • 12. Using the Data @brianhogg WordCamp Buffalo Sep 2013 12  Simple front-end pop-up  Using WP_Query (meta_query)  Hooks to store in separate, indexed table  Custom feeds  …
  • 13. Using the Data @brianhogg WordCamp Buffalo Sep 2013 13  Simple front-end pop-up
  • 14. Using the Data @brianhogg WordCamp Buffalo Sep 2013 14  Database query  Get location of user  Restrict posts using a “bounding box”  Ordering by distance from a lat/lon
  • 15. Using the Data @brianhogg WordCamp Buffalo Sep 2013 15  Using WP_Query (meta_query)
  • 16. Using the Data @brianhogg WordCamp Buffalo Sep 2013 16  Bounding box query
  • 17. Using the Data @brianhogg WordCamp Buffalo Sep 2013 17  Using WP_Query
  • 19. Using the Data @brianhogg WordCamp Buffalo Sep 2013 19  Using WP_Query
  • 21. Using the Data @brianhogg WordCamp Buffalo Sep 2013 21 SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id) LEFT JOIN wp_geo geo ON wp_posts.ID = geo.post_id WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( (wp_postmeta.meta_key = 'geo_latitude' AND CAST(wp_postmeta.meta_value AS DECIMAL) BETWEEN '42' AND '43') AND (mt1.meta_key = 'geo_longitude' AND CAST(mt1.meta_value AS DECIMAL) BETWEEN '-79.9999' AND '-78') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 15  Sample WP_Query SQL (bounding box)
  • 22. Using the Data @brianhogg WordCamp Buffalo Sep 2013 22  WP_Query method very inefficient especially with larger amounts of data  Separate table can be used with an index, numeric data format
  • 23. Using the Data @brianhogg WordCamp Buffalo Sep 2013 23  Create a new indexed table in the database  Create a WP hook to store in the new table CREATE TABLE IF NOT EXISTS `wp_geo` ( `post_id` bigint(20) unsigned NOT NULL, `lat` float NOT NULL, `lon` float NOT NULL, PRIMARY KEY (`post_id`), KEY `latlon` (`lat`,`lon`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  • 25. Using the Data @brianhogg WordCamp Buffalo Sep 2013 25
  • 26. Using the Data @brianhogg WordCamp Buffalo Sep 2013 26  posts_clauses filter
  • 27. Using the Data @brianhogg WordCamp Buffalo Sep 2013 27
  • 28. Using the Data @brianhogg WordCamp Buffalo Sep 2013 28
  • 29. Using the Data @brianhogg WordCamp Buffalo Sep 2013 29  Custom feeds  Page templates  Caching?
  • 30. Using the Data @brianhogg WordCamp Buffalo Sep 2013 30  Create map markers from one or more JSON based feeds
  • 31. Getting Visitor Location @brianhogg WordCamp Buffalo Sep 2013 31  IP address (approximate)  GPS  Google Maps API
  • 32. Getting Visitor Location @brianhogg WordCamp Buffalo Sep 2013 32  IP address (approximate)  MaxMind – www.maxmind.com  HostIP - http://www.hostip.info/use.html  http://ipinfodb.com/ip_location_api.php  Javascript request (navigator.geolocation)
  • 33. @brianhogg WordCamp Buffalo Sep 2013 33 Resources / Contact brian@bhconsulting.ca @brianhogg

Editor's Notes

  1. Not really the mapping side, but storing and using the data and making it easy for end-user to maintain… can talk after
  2. … but relatively new to Wordpress
  3. There are limits to how many times you can call this per day, API key, etc
  4. pre_get_posts
  5. URL of theory there (Java code example) – “GREAT CIRCLE” approximation/projection -- Any mistakes? Let me know 
  6. Template tag or something.. -- IF ALREADY HAVE POSTS - Problem with sorting on PHP side – 1000’s of records, getting just one page? Have to sort all of them each time --- especially if no distance.
  7. Create a hook on activation of the plugin, and to import existing post meta values… 2) can drop on deactivation, too
  8. Other conditions to save geolocation can add… Assumes post meta data is already saved, works alright if only using the WP UI, otherwise need to use updated_post_meta
  9. Don’t have to add the WHERE necessarily – and COULD just use $wpdb and a custom query depending on where you’ll be using the data
  10. LIMIT and other clauses stay the same, so integrates into existing site / feed
  11. Could do something as simple as an is_admin() check --- return $clauses !!! If this is FALSE (Mo)
  12. CUSTOM FEED “CACHING” – clear your browser! /// Google Maps API, Open Street Map (open source alternative)
  13. Don’t even necessarily need a front-end website – easy way for clients to maintain the geographic data (WP posts)
  14. Geo data store --- one meta key, but gives the idea