SlideShare a Scribd company logo
GEOLOCATION
Timothy Boronczyk
Syracuse PHP Users Group
September 29, 2016
Timothy Boronczyk
Senior Developer at Optanix, Inc.
Former Managing Editor of phpmaster.com
Author
 CentOS 7 Server Deployment Cookbook
 Jump Start MySQL
 Beginning PHP6, Apache, MySQL Web Development
 PHP and MySQL: Create, Modify, Reuse
zaemis.blogspot.com @zaemis
Geolocation describes the
real-world position of objects
using coordinates.
Geodetic Systems
Latitude and Longitude
Geodetic Systems
CH1903
ED 50
ETRS89
GCJ-02
GDA94
JGD2011
NAD83
OSGB36
RT90
SAD69
WGS84
IP-based geolocation uses the
user’s IP address to determine
their general location.
Database Web Service
 IP2Location
 MaxMind GeoIP2
 MaxMind GeoLite2
 MaxMind GeoIP2
Precision Services
 Neustar IP Intelligence
 ipinfo.io
 geoPlugin.com
use GeoIp2DatabaseReader;
$reader = new Reader('Geolite2-City.mmdb');
$record = $reader->city($_SERVER['REMOTE_ADDR']);
$city = $record->city->name;
$state = $record->mostSpecificSubdivision->name;
$img = imagecreatefromjpeg('singles.jpg');
for ($i = 0; $i < $numProfiles; ++$i) {
$x = $startX + ($profileWidth * $i);
imagettftext($img, $fontSize, 0, $x, $cityY, $color, $font, $city);
$x = $startX + ($profileWidth * $i);
imagettftext($img, $fontSize, 0, $x, $stateY, $color, $font, $state);
}
header('Content-Type: image/jpeg');
imagejpeg($img);
GeoLite2 City Database
city->geonameid
city->name
continent->code
continent->geonameid
continent->name
country->geonameid
country->isoCode
country->name
location->accuracyRadius
location->latitude
location->longitude
location->metroCode
location->timeZone
postal->code
subdivisions[]->geonameId
subdivisions[]->isoCode
subdivisions[]->name
mostSpecificSubdivision->*
geoPlugin.com Web Service
www.geoplugin.net/json.gp?ip=<ADDRESS>
geoplugin_latitude
geoplugin_longitude
geoplugin_regionCode
geoplugin_regionName
geoplugin_currencyCode
geoplugin_currencySymbol
geoplugin_city
geoplugin_region
geoplugin_areaCode
geoplugin_dmaCode
geoplugin_countryCode
geoplugin_countryName
geoplugin_continentCode
IP-based geolocation
is imprecise.
The JavaScript geolocation API
provides more accurate
location information.
var map = L.map(document.getElementById("map"));
map.addLayer(L.stamenTileLayer("terrain"));
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function (pos) {
var lat = pos.coords.latitude;
var lon = pos.coords.longitude;
var acc = pos.coords.accuracy;
map.setView([lat, lon], 16);
L.circle([lat, lon], acc).addTo(map);
L.marker([lat, lon]).addTo(map);
},
function (err) {
console.warn("Error: " + err.message);
},
{enableHighAccuracy: true}
)
}
The Geolocation Privacy and
Surveillance Act proposes
guidelines for how location
Information can be used.
Distance Formulas
 Pythagorean Theorem
 Spherical Law of Cosines
 Haversine Formula
 Vincenty’s Formulas
Spherical Law of Cosines
d = R· arccos(sin φ1· sin φ2 + cos φ1· cos φ2· cos Δλ)
Use a minimum bounding
rectangle to narrow results.
MBR Coordinates
φ2 = arcsin(sin φ1· cos δ + cos φ1· sin δ · cos θ)
λ2 = λ1 + atan2(sin θ· sin δ· cos φ1, cos δ - sin φ1· sin φ2)
function distance($lat1, $lon1, $lat2, $lon2) {
$rLat1 = deg2rad($lat1);
$rLat2 = deg2rad($lat2);
$rLonDelta = deg2rad($lon2 - $lon1);
return WGS84_RADIUS * acos(sin($rLat1) * sin($rLat2) +
cos($rLat1) * cos($rLat2) * acos($rLonDelta));
}
function destination($lat, $lon, $bearing, $dist) {
$rLat = deg2rad($lat);
$rLon = deg2rad($lon);
$bearing = deg2rad($bearing);
$angDist = $dist / WGS84_RADIUS;
$lat2 = asin(sin($rLat) * cos($angDist) +
cos($rLat) * sin($angDist) * sin($bearing));
$lon2 = $rLon + atan2(sin($rBearing) * sin($angDist) * cos($rLat),
cos($angDist) - sin($rLat) * sin($lat2));
return [deg2rad($lat2), deg2rad($lon2)];
}
function bounds($lat, $lon, $dist) {
$lat1 = destination($lat, $lon, 0, $dist)[0];
$lon1 = destination($lat, $lon, 90, $dist)[1];
$lat2 = destination($lat, $lon, 180, $dist)[0];
$lon2 = destination($lat, $lon, 270, $dist)[1];
return [
min($lat1, $lat2), max($lat1, $lat2),
min($lon1, $lon2), max($lon1, $lon2)
];
}
$rect = bounds($_GET['lat'], $_GET['lon'], $_GET['radius']);
$query = "SELECT name, address, city, state, zip_code, latitude, longitude
FROM libraries WHERE latitude BETWEEN {$rect[0]} AND {$rect[1]} AND
longitude BETWEEN {$rect[2]} AND {$rect[3]}";
$result = $db->query($query);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$dist = distance($_GET['lat'], $row['latitude'], $row[’longitude']);
if ($dist <= $_GET['radius']) {
$libraries[] = $row;
}
}
MySQL has implemented some
of the Open Geospatial
Consortium’s spatial extensions.
Thanks for coming!
Questions?

More Related Content

What's hot

Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
 Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt... Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
Databricks
 
Sydney GeoRabble Presentation - GovHack 2012 - Happiness Matters
Sydney GeoRabble Presentation - GovHack 2012 - Happiness MattersSydney GeoRabble Presentation - GovHack 2012 - Happiness Matters
Sydney GeoRabble Presentation - GovHack 2012 - Happiness Matters
Kelvin Nicholson
 
Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010 Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010
Skills Matter
 
No more (unsecure) secrets, Marty
No more (unsecure) secrets, MartyNo more (unsecure) secrets, Marty
No more (unsecure) secrets, Marty
Mathias Herberts
 
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Databricks
 
Ordered Record Collection
Ordered Record CollectionOrdered Record Collection
Ordered Record Collection
Hadoop User Group
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
Ryan Anklam
 
Interface record comparator
Interface record comparatorInterface record comparator
Interface record comparatormyrajendra
 
Ignite es6
Ignite es6Ignite es6
Ignite es6
jstack
 
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Nikita Koksharov
 
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Daniel Luxemburg
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Citus Data
 
RedisConf17 - Distributed Java Map Structures and Services with Redisson
RedisConf17 - Distributed Java Map Structures and Services with RedissonRedisConf17 - Distributed Java Map Structures and Services with Redisson
RedisConf17 - Distributed Java Map Structures and Services with Redisson
Redis Labs
 
Coordination of Distributed Software with Redis
Coordination of Distributed Software with RedisCoordination of Distributed Software with Redis
Coordination of Distributed Software with Redis
Konrad Bucheli
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
C4Media
 
ns2 install
ns2 installns2 install
ns2 install
HUANG HSITING
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScriptRaphael Cruzeiro
 
NS & NSID of Amazon Route 53
NS & NSID of Amazon Route 53NS & NSID of Amazon Route 53
NS & NSID of Amazon Route 53
@ otsuka752
 

What's hot (20)

Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
 Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt... Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
Apply Hammer Directly to Thumb; Avoiding Apache Spark and Cassandra AntiPatt...
 
Sydney GeoRabble Presentation - GovHack 2012 - Happiness Matters
Sydney GeoRabble Presentation - GovHack 2012 - Happiness MattersSydney GeoRabble Presentation - GovHack 2012 - Happiness Matters
Sydney GeoRabble Presentation - GovHack 2012 - Happiness Matters
 
Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010 Daniel Sikar: Hadoop MapReduce - 06/09/2010
Daniel Sikar: Hadoop MapReduce - 06/09/2010
 
No more (unsecure) secrets, Marty
No more (unsecure) secrets, MartyNo more (unsecure) secrets, Marty
No more (unsecure) secrets, Marty
 
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
 
Ordered Record Collection
Ordered Record CollectionOrdered Record Collection
Ordered Record Collection
 
Add Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJSAdd Some Fun to Your Functional Programming With RXJS
Add Some Fun to Your Functional Programming With RXJS
 
Interface record comparator
Interface record comparatorInterface record comparator
Interface record comparator
 
Ignite es6
Ignite es6Ignite es6
Ignite es6
 
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
 
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
 
RedisConf17 - Distributed Java Map Structures and Services with Redisson
RedisConf17 - Distributed Java Map Structures and Services with RedissonRedisConf17 - Distributed Java Map Structures and Services with Redisson
RedisConf17 - Distributed Java Map Structures and Services with Redisson
 
Coordination of Distributed Software with Redis
Coordination of Distributed Software with RedisCoordination of Distributed Software with Redis
Coordination of Distributed Software with Redis
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 
ns2 install
ns2 installns2 install
ns2 install
 
ns2-training material
ns2-training materialns2-training material
ns2-training material
 
What they don't tell you about JavaScript
What they don't tell you about JavaScriptWhat they don't tell you about JavaScript
What they don't tell you about JavaScript
 
NS & NSID of Amazon Route 53
NS & NSID of Amazon Route 53NS & NSID of Amazon Route 53
NS & NSID of Amazon Route 53
 

Similar to Geolocation

Sample document
Sample documentSample document
Sample document
arunsethu87
 
Geo distance search with my sql presentation
Geo distance search with my sql presentationGeo distance search with my sql presentation
Geo distance search with my sql presentationGSMboy
 
OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011chelm
 
Geolocation on Rails
Geolocation on RailsGeolocation on Rails
Geolocation on Railsnebirhos
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecast
Masahiro Nagano
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
Mark Rees
 
Perl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReducePerl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReduce
Pedro Figueiredo
 
Server side geo_tools_in_drupal_pnw_2012
Server side geo_tools_in_drupal_pnw_2012Server side geo_tools_in_drupal_pnw_2012
Server side geo_tools_in_drupal_pnw_2012
Mack Hardy
 
Saving Gaia with GeoDjango
Saving Gaia with GeoDjangoSaving Gaia with GeoDjango
Saving Gaia with GeoDjango
Calvin Cheng
 
Postgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial ExtensionsPostgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial Extensions
EDB
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
Harun Yardımcı
 
2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator
Alberto Paro
 
2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator
Alberto Paro
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
tarifarmarie
 
10. R getting spatial
10.  R getting spatial10.  R getting spatial
10. R getting spatial
ExternalEvents
 
Geopy module in python
Geopy module in pythonGeopy module in python
Geopy module in python
Ashmita Dhakal
 
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
GIS in the Rockies
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
FAO
 
Location based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagLocation based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tag
Microsoft Mobile Developer
 
Full stack analytics with Hadoop 2
Full stack analytics with Hadoop 2Full stack analytics with Hadoop 2
Full stack analytics with Hadoop 2
Gabriele Modena
 

Similar to Geolocation (20)

Sample document
Sample documentSample document
Sample document
 
Geo distance search with my sql presentation
Geo distance search with my sql presentationGeo distance search with my sql presentation
Geo distance search with my sql presentation
 
OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011
 
Geolocation on Rails
Geolocation on RailsGeolocation on Rails
Geolocation on Rails
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecast
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
 
Perl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReducePerl on Amazon Elastic MapReduce
Perl on Amazon Elastic MapReduce
 
Server side geo_tools_in_drupal_pnw_2012
Server side geo_tools_in_drupal_pnw_2012Server side geo_tools_in_drupal_pnw_2012
Server side geo_tools_in_drupal_pnw_2012
 
Saving Gaia with GeoDjango
Saving Gaia with GeoDjangoSaving Gaia with GeoDjango
Saving Gaia with GeoDjango
 
Postgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial ExtensionsPostgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial Extensions
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
 
2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator
 
2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator2017 02-07 - elastic & spark. building a search geo locator
2017 02-07 - elastic & spark. building a search geo locator
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
 
10. R getting spatial
10.  R getting spatial10.  R getting spatial
10. R getting spatial
 
Geopy module in python
Geopy module in pythonGeopy module in python
Geopy module in python
 
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
 
Location based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagLocation based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tag
 
Full stack analytics with Hadoop 2
Full stack analytics with Hadoop 2Full stack analytics with Hadoop 2
Full stack analytics with Hadoop 2
 

Recently uploaded

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 

Recently uploaded (20)

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 

Geolocation

Editor's Notes

  1. Coordinates are a set of values used to identify the location of an object. They allow us to answer the question “Where am I?” Coordinate systems provide context for working with locations. There are different coordinate systems but they all include: origin, distance, and direction. Example: an object is 5 steps (distance) in front (direction) of me (origin). Coordinates also allow us to answer the question “Where will I be?” Examples: I move 4 steps forward and 3 steps to my right I turn 30 degrees to my right and walk for 8 steps A whole branch of mathematics is based on angle/distance (trigonometry). Drawing a line from the point to the origin forms an angle with the X axis. The point’s Y coordinate is the angle’s sine. The point’s X coordinate is the angle’s cosine.
  2. Coordinate systems that identify locations on Earth are known as geodetic systems. Geodetic systems use latitude and longitude to specify coordinates. Latitude runs east-west as parallel rings. 0° latitude is the Equator +90° is the North Pole; -90° is the South Pole Longitude lines circle the earth at angles around the poles. 0° longitude is the Prime Meridian Positive values are east; negative values are west The 180th meridian is the Antimeridian  The distance between two longitude lines near the equator is not the same as near the poles
  3. Different geodetic systems use slightly different positions for 0° latitude and 0° longitude, as well different reference values like the Earth’s diameter, for more accurate results in different parts of the world. Examples: CH1903–Swiss Grid ED 50–European Datum ETRS89–European Terrestrial Reference System GCJ-02–Chinese Encrypted Geodetic Datum GDA94– Geocentric Datum of Australia JGD2011– Japanese Geodetic Datum (adjusted for changes caused by 2011 earthquake and tsunami) NAD83–North American Datum OSGB36–Ordnance Survey of Great Britain RT 90–Swedish Grid (Rikets Nät) SAD69–South American Datum  WGS84–World Geodetic System Additional geodetic systems can be found online at epsg.io. Different systems are needed because the Earth is not perfectly round—the distance from its center to sea level is 13 miles greater at the equator than at the poles. Adoption of WGS84 is increasing because the benefits of a global system outweigh greater accuracy.
  4. Server-side, we don’t know the exact location of a user unless they tell us. However, we may be able to get a rough idea from their IP address. Location databases relate IP address to a general area (i.e., city or state) and other related information (area code, latitude and longitude of the city’s center, etc.) Use cases for IP-based geolocation: Digital rights management (boo!) Provide relative content (news stories, all search is local) Fraud detection/prevention Marketing/demographics
  5. Databases can be self-hosted or accessed via a web service. Databases: IP2Location MaxMind GeoIP2 MaxMind GeoLite2 – free City and Country databases   Web Services: MaxMind GeoIP2 Precision Services Neustar IP Intelligence ipinfo.io – free, 1000 requests a day geoPlugin.com – free, 10 requests per minute   In general, a paid database/service will have more information and more frequent updates. Free offerings are more limited, may have usage restrictions, and are unsupported.
  6. Example of IP-based geolocation: Sexy Singles Prepare a base image Look up the user’s IP address in the database and retrieve the name of their city Draw the name on the image
  7. Instantiate the Reader object with the path to the database file and then provide the IP address to the appropriate method (city() is using the City database, country() if using the Country database, etc.)   The Reader class works with both GeoLite2 City and Country databases and GeoIP2 databases. To use the web service instead, instantiate GeoIP2\WebService\Client with a user ID and license key and then provide the address to the appropriate method.
  8. The GeoLite2 City database used in the demo contains the following information: city->geoname city->name continent->code continent->geoname continent->name country->geonameid country->isoCode country->name location->accuracyRadius location->latitude location->longitude location->metroCode location->timeZone postal->code subdivisions[]->geonameId subdivisions[]->isoCode subdivisions[]->name mostSpecificSubdivision->* The paid GeoIP2 City database also includes: location->averageIncome location->populationDensity
  9. The website for the geoPlugin web service hosts a class file for working with the service, but its just as easy to issue a curl call or use file_get_contents() to retrieve data. $record = json_decode(file_get_contents(     'http://www.geoplugin.net/json.gp?ip=' . $_SERVER['REMOTE_ADDR'])); • json.gp returns a JSON string • php.gp returns a serialized PHP array • xml.gp returns an XML document API key can be purchased for SSL for 12€ (~$13) The geoPlugin service returns the following information: • geoplugin_city • geoplugin_region • geoplugin_areaCode • geoplugin_dmaCode • geoplugin_countryCode • geoplugin_countryName • geoplugin_continentCode • geoplugin_latitude • geoplugin_longitude • geoplugin_regionCode • geoplugin_regionName • geoplugin_currencyCode • geoplugin_currencySymbol
  10. IP-based geolocation is inherently imprecise. Things to be aware of: An address can only be mapped to a general area. The returned latitude and longitude is the center of the area The database can become outdated (example: Verizon re-allocates on of its address blocks to a different part of their network) The address will not be the user’s real IP address if they are behind a proxy
  11. The JavaScript geolocation API gives developers access to more accurate location information. Supported by: • Firefox 3.5+ • Chrome 5.0+ • Safari 5.0+ • Opera 10.60+ • IE 9+ • Android 2.0+ • iPhone 3.0+ The platform can use different methods to determine a user’s location: • Google Location Service database (uses visible Wi-Fi networks, signal strength, MAC addresses, etc.) • GPS receiver • Cell towers (triangulation)
  12. Example of location detection using JavaScript API
  13. navigator.geolocation: • getCurrentPosition(success, error, options) • watchPosition(success, error, options) • clearWatch(id)
  14. The browser prompts the user before sharing their location for privacy reasons. Graceful degradation/progressive enhancement — consider using IP-based location first and use the JavaScript geolocation API for greater resolution.
  15. The Geolocation Privacy and Surveillance Act (GPS Act) was introduced to Congress in June 2011. The act is “a legal framework designed to give government agencies, commercial entities and private citizens clear guidelines for when and how geolocation information can be accessed and used.” The Obama Administration opposes the act because GPS tracking is “no more invasive than visual surveillance.”
  16. Once we have the user’s coordinates, we can calculate the distance between them and another object’s position. The pythagorean theorem can be used for small areas where the curvature of the earth is not a factor (indoor). Other formulas for calculating distances on a sphere: • Spherical Law of Cosines • Haversine Formula • Vincenty’s Formulas Choosing a formula to use depends on the required level of accuracy and computation speed. Suggested Resources: • www.movable-type.co.uk/scripts/latlong.html - Calculate distance, bearing and more between Latitude/Longitude points • gis.stackexchange.com/q/4906 - Why is law of cosines more preferable than haversine when calculating distance between two latitude-longitude points?
  17. The Spherical Law of Cosines states the distance between two points ((AB)) on a sphere is the same as the measure of the angle they form (∠ACB) to the center of the sphere (C). d = R ⋅ arccos( sin φ1 ⋅ sin φ2 + cos φ1 ⋅ cos φ2 ⋅ cos Δλ ) d Distance R Radius (3,963.19 miles per WGS84) φ (phi) Latitude λ (lambda) Longitude Note: Latitude and longitude are expressed in degrees but the trigonometric functions expect values in radians; use deg2rad() to convert them.
  18. Assume we have a database of records for objects with their locations and we want to retrieve records for those objects within a given distance—calculating the distance for every location to filter the results is inefficient. Use a minimum bounding rectangle to narrow search results. Strategy: • Calculate a minimum bounding rectangle • Select records that fall within the rectangle • Use the distance formula to narrow down the results We cannot simply say 1 mile = 0.001 degree because the distance between two lines of longitude vary depending on latitude. A bounding rectangle requires calculating coordinates at a certain distance in the different direction.
  19. I assume one can rewrite the distance equation to solve for different variables but my trigonometry skills are rusty. Wolfram-Alpha results were scary. An internet search returned these formulas (www.movable-type.co.uk/ scripts/latlong.html): φ2 = asin(sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ) λ2 = λ1 + atan2(sin θ ⋅ sin δ ⋅ cos φ1, cos δ - sin φ1 ⋅ sin φ2) δ (delta) is d/R (angular radius) Θ (theta) is angle of direction (0° = east, 90° = north, 180° = west, 270° = south) atan2 is arctan that accepts two arguments (i.e. coordinates X, Y) • signs the arctan result depending on where the point lies in the coordinate system, positive to the top/right and negative to the bottom/left. • Wolfram’s results were scary because it was performing the underlying mathematical acrobatics of atan2.
  20. Example of searching for nearby libraries
  21. The Open Geospatial Consortium defined an extension to SQL to support spatial data. MySQL implements some of the definition.   MySQL 5.7 or newer is required. • It was not possible to create spatial indexes prior to 5.7. • 5.7 implemented st_distance_sphere() which calculates the distance between two points on a sphere; other distance functions use planer geometry   Recommended reading: www.percona.com/blog/2016/02/03/new-gis-features-in-mysql-5-7