130 likes | 663 Views
Google Maps API. Calculating driving distance between two places. Google Distance Matrix API. https://developers.google.com/maps/documentation/distancematrix/. Google Maps Directions. Google Distance Matrix API. http://maps.googleapis.com/maps/api/distancematrix/xml
E N D
Google Maps API Calculating driving distance between two places
Google Distance Matrix API https://developers.google.com/maps/documentation/distancematrix/
Google Distance Matrix API http://maps.googleapis.com/maps/api/distancematrix/xml ?origins=Halifax+NS&destinations=Sydney+NS&mode=driving&sensor=false
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> <status>OK</status> <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>
Ingredients • filename url “http:// …” • infilerecfm=s /* read as stream */ • Regular expressions to process XML • prxparse • prxmatch • prxposn
%macrogmapsdist (ORIG, DEST); %let URL = str(http://maps.googleapis.com/maps/api/distancematrix/xml ?origins=)&ORIG. %nrstr(&destinations=)&DEST. %nrstr(&mode=driving&sensor=false); filename gmapsurl"&URL"; data _null_; /* Regular expression pattern to match XML tags and pull out distance value */ regex = prxparse("/\<distance>\s*\<value>(\d+)\<\/value>/"); infilegmapsrecfm=s lrecl=32767; input; if prxmatch(regex, _infile_) then distance = prxposn(regex, 1, _infile_); put distance; run; %mendgmapsdist;
Resources • Driving Distances and Times, Using SAS® and Google Maps, Mike Zdeb • University at Albany, School of Public Health • Paper 043-29 An Introduction to Regular Expressions with Examples from Clinical Data, Richard Pless, Ovation Research Group, Highland Park, IL • Paper 119-29 Reading and Writing XML files from SAS®, Miriam Cisternas, Ovation Research Group, Carlsbad, CA Ricardo Cisternas, MGC Data Services, Carlsbad, CA • Paper 121-2012,Accessing and Extracting Data from the Internet Using SASR, George Zhu, SunitaGhosh, Alberta Health Services - Cancer Care