Presentation is loading. Please wait.

Presentation is loading. Please wait.

Calculating driving distance between two places

Similar presentations


Presentation on theme: "Calculating driving distance between two places"— Presentation transcript:

1 Calculating driving distance between two places
Google Maps API Calculating driving distance between two places

2 Google Distance Matrix API

3 Google Maps Directions

4 Google Distance Matrix API
?origins=Halifax+NS&destinations=Sydney+NS&mode=driving&sensor=false

5 API returns XML … How to get values into SAS?
<DistanceMatrixResponse> <status>OK</status> <origin_address>Halifax, NS, Canada</origin_address> <destination_address>Truro, NS Canada</destination_address> <row> <element> <duration> <value>4167</value> <text>1 hour 9 mins</text> </duration> <distance> <value>94230</value> /* metres */ <text>94.2 km</text> </distance> </element> </row> </DistanceMatrixResponse>

6 Ingredients filename url “http:// …”
infile recfm=s /* read as stream */ Regular expressions to process XML prxparse prxmatch prxposn

7 %macro gmapsdist (ORIG, DEST); %let URL = str(http://maps. googleapis
%macro gmapsdist (ORIG, DEST); %let URL = str( ?origins=)&ORIG. %nrstr(&destinations=)&DEST. %nrstr(&mode=driving&sensor=false); filename gmaps url "&URL"; data _null_; /* Regular expression pattern to match XML tags and pull out distance value */ regex = prxparse("/\<distance>\s*\<value>(\d+)\<\/value>/"); infile gmaps recfm=s lrecl=32767; input; if prxmatch(regex, _infile_) then distance = prxposn(regex, 1, _infile_); put distance; run; %mend gmapsdist;

8 Resources Driving Distances and Times, Using SAS® and Google Maps, Mike Zdeb University at Albany, School of Public Health Paper An Introduction to Regular Expressions with Examples from Clinical Data, Richard Pless, Ovation Research Group, Highland Park, IL Paper Reading and Writing XML files from SAS®, Miriam Cisternas, Ovation Research Group, Carlsbad, CA Ricardo Cisternas, MGC Data Services, Carlsbad, CA Paper ,Accessing and Extracting Data from the Internet Using SASR, George Zhu, Sunita Ghosh, Alberta Health Services - Cancer Care


Download ppt "Calculating driving distance between two places"

Similar presentations


Ads by Google