Problem Statement:
You have addresses and you need to identify GPS co-ordinates and calculate the driving time and duration between two points. Using the Alteryx distance tool, you get the straight line distance instead of the drive route. You can use Google Maps API to calculate the distance but it has a limitation of certain number of requests per day on its free account that’s when Bing Map API comes in.
Pre-requisites:
Bing API Key which can be obtained from https://www.bingmapsportal.com/
Information is available on https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/getting-a-bing-m...
Solution:
If you have addresses and you want to get the distance and driving time between these address.
DepartFrom | ArriveAt |
You Yangs Regional Park, Branch Rd, Little River VIC 3211, Australia | Kinglake National Park, Kinglake West VIC 3757, Australia |
Step 1: Prepare the data
Prepare your data in the following format for ease
Step 2: Identify the Lat/Long of the addresses
Create a bing API request in the following format.
"http://dev.virtualearth.net/REST/v1/Locations?countryRegion="+[countryRegion]+"&adminDistrict="+[State]+"&locality="+[Locality]+"&postalCode="+[Postcode]+"&addressLine="+[addressLine]+"&maxResults=1&o=xml&key="+[bingmaps.key]
Where;
[countryRegion]
[State]
[Locality]
[Postcode]
[addressLine]
[bingmaps.key]
are the variables
Field Name | Field Value |
RecordID | 1 |
DepartFrom | You Yangs Regional Park, Branch Rd, Little River VIC 3211, Australia |
addressLine | You Yangs Regional Park |
Locality | Little River |
countryRegion | Australia |
Postcode | 3211 |
State | VIC |
bingmaps.key | <your bing API key> |
pointURL | http://dev.virtualearth.net/REST/v1/Locations?countryRegion=Australia&adminDistrict=VIC&locality=Lit... River&postalCode=3211&addressLine=You Yangs Regional Park&maxResults=1&o=xml&key=<your bing API key> |
Download the alteryx workflow to understand how I created an API request. Repeat the same steps for Destination.
I used formula tool to create these fields and download tool to send the API request.
Step 3: Calculate the driving time and driving duration between the two GPS locations
Once you have the Origin/Destination Lats/Longs, send the API request to get the distance and duration using the following URL request.
"https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?origins="+[Origin]+"&destinations="+[Destination]+"&travelMode="+[travelMode]+"&o=xml&key="+[bingmaps.key]
Where;
[Origin]
[Destination]
[travelMode]
[bingmaps.key]
are variables.
Next use the XML parse tool to read Distance and Duration
Hi @DiganP,
Thats right. Distance Tool gives you straight line distance which is not the driving distance. And for TomTom, you need Alteryx Geospatial License.
Is this process possible to use for batches of address data? ie thousands of addresses, or is there a limit allowed with the Bing API key?
Also, when creating the Bing Key, what application type should be set? There is Mobile, Wesbite, DevTest or Windows Application
Hi @AMackay:
I have tried with 50k+ addresses and it worked for me. Use Dev/Test (Key type: Basic / Dev/Test).
Hi @alibink
I am trying to use your tool but I am able to download only Latitude value and no long. value as shown below.
I observed that, usage type is missing. could you please help in fixing this?
hi Alibink
did you have a solution for the issue that was faced by Raj from below?basically the download tool brings the whole html, but when its parsed in the html tool only the latitude is parsed, also when I look inside of the xml being outputted the usage type is actually "Display" in all the cases the usage type is not parsed in the xml tool either.
any one knows why?