Geocoding Address
Get latitude, longitude and other address related information from the MapQuest Geocoding 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 |
CREATE PROCEDURE usp_MapQuest_Geocoding_Address(@Address varchar(40), @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS DECLARE @URLnvarchar(MAX) DECLARE @QueryString varchar(MAX) DECLARE @HTTPSessionID uniqueidentifier SET @URL = 'http://www.mapquestapi.com/geocoding/v1/address' EXEC SQLHTTP.net.QueryStringBuilder @QueryString OUTPUT, 'MapQuest', 'key', '#APIKey', 'location', @Address 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 30 31 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) EXEC usp_MapQuest_Geocoding_Address @Address = '233 S Wacker Dr, Chicago, IL', @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 latLng_lat, latLng_lng, locations_mapUrl, locations_street, locations_postalCode, locations_adminArea1Type, locations_adminArea1, locations_adminArea3Type, locations_adminArea3, locations_adminArea4Type, locations_adminArea4, locations_adminArea5Type, locations_adminArea5, locations_adminArea6Type, locations_adminArea6 FROM ##MapQuestAPITempGlobalTable WHERE latLng_lat IS NOT NULL DROP TABLE ##MapQuestAPITempGlobalTable END |
1 2 3 4 5 6 |
latLng_lat latLng_lng locations_mapUrl locations_street locations_postalCode locations_adminArea1Type locations_adminArea1 locations_adminArea3Type locations_adminArea3 locations_adminArea4Type locations_adminArea4 locations_adminArea5Type locations_adminArea5 locations_adminArea6Type locations_adminArea6 --------------- --------------- ----------------------- ----------------------- ----------------------- ------------------------------- ----------------------- ------------------------------- ----------------------- ------------------------------- ----------------------- ------------------------------- ----------------------- ------------------------------- --------------------------- 41.878869 -87.636739 http://www.mapquest... 233 S Wacker Dr 60606-1900 Country US State IL County Cook City Chicago Neighborhood |
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.