Directions Route
Get step-by-step driving instructions from the MapQuest Directions API using SQL Server.
- See SQLHTTP easy setup for MapQuest API
- See API Call documentation for parameter values and other information
- Create the stored procedure documented below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
CREATE PROCEDURE usp_MapQuest_Directions_Route( @From varchar(100), @To varchar(100), @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS DECLARE @URL nvarchar(MAX) DECLARE @QueryString varchar(MAX) DECLARE @HTTPSessionID uniqueidentifier SET @URL = 'http://www.mapquestapi.com/directions/v2/route' EXEC SQLHTTP.net.QueryStringBuilder @QueryString OUTPUT, 'MapQuest', 'key', '#APIKey', 'from', @From, 'to',@To SET @URL = @URL + @QueryString; EXEC SQLHTTP.net.HTTPSession @HTTPSessionID OUTPUT EXEC SQLHTTP.net.HTTPRequest @HttpSessionID, @URL = @URL, @Method = 'GET', @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT, @Response = @Response OUTPUT GO |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) EXEC usp_MapQuest_Directions_Route @From = '100 Mt Diablo Blvd, Walnut Creek, California', @To = '3200 Telegraph Ave, Berkeley', @Response = @Response OUTPUT, @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT IF @StatusCode >= 400 EXEC SQLHTTP.net.RaiseHttpError @StatusCode, @StatusDescription, @Response ELSE BEGIN EXEC SQLHTTP.net.Json_To_GlobalTable @Response, 'MapQuestAPITempGlobalTable' SELECT maneuvers_index, startPoint_lat, startPoint_lng, maneuvers_mapUrl, maneuvers_narrative FROM ##MapQuestAPITempGlobalTable WHERE startPoint_lat IS NOT NULL ORDER BY maneuvers_index DROP TABLE ##MapQuestAPITempGlobalTable END |
1 2 3 4 5 6 7 8 9 10 |
maneuvers_index startPoint_lat startPoint_lng maneuvers_mapUrl maneuvers_narrative ------------------ ------------------- ---------------- ----------------------- ------------------------------------------------------------------------ 0 37.898929 -122.056175 http://www.mapquest... Start out going southwest on Mt Diablo Blvd toward Iron Horse Trl. 1 37.896583 -122.071571 http://www.mapquest... Merge onto CA-24 W. 2 37.843555 -122.254959 http://www.mapquest... Take the Telegraph Avenue exit, EXIT 3. 3 37.841785 -122.261611 http://www.mapquest... Turn right onto Telegraph Ave. 4 37.852821 -122.260147 http://www.mapquest... Make a U-turn at Woolsey St onto Telegraph Ave. 5 37.852943 -122.260177 http://www.mapquest... 3200 TELEGRAPH AVE is on the right. |
IMPORTANT DISCLAIMER
CODE/SQL ON THESE PAGES ARE PROVIDED AS-IS AND ARE AVAILABLE FOR ILLUSTRATIVE PURPOSES ONLY.
USERS ARE REQUIRED TO ABIDE BY THE TERMS AND CONDITIONS FOR USING REFERENCED THIRD PARTY WEBSITES AND/OR APIs FROM THEIR RESPECTIVE WEBSITES. WE DO NOT CONDONE ANY VIOLATION OF THIRD PARTY WEBSITES AND/OR APIs TERMS AND CONDITIONS USING OUR SOFTWARE.
USERS SHALL BE SOLELY RESPONSIBLE AND BE SOLELY LIABLE FOR VIOLATION OF ANY RULES SPECIFIED BY THIRD PARTIES FOR USING THEIR WEBSITES AND/OR APIs, OR INFRINGEMENT OF RIGHTS OF SUCH THIRD PARTIES.