SQL Server : scalar function XML Result google maps api -


i'm trying reverse geocoding via google api , full address result of api, i'm going use sql server 2012 because have database on , need generate report existing lat/lon in database need function in sql result .

i have sql query result without error

declare @lat nvarchar(50),@lon nvarchar(50) set @lat = '22.298828' set @lon = '114.172596'   declare  @xml table ( yourxml xml ) declare @url varchar(max)   declare @qs varchar(50) select @qs = '&date='+convert(varchar(25),getdate(),126) select @url = 'http://maps.google.com/maps/api/geocode/xml?latlng=' + @lat + ',' + @lon + '&sensor=false'  + @qs  declare @response varchar(max) declare @mxml xml declare @obj int  declare @result int  declare @httpstatus int  declare @errormsg varchar(max)  begin try exec @result = sp_oacreate 'msxml2.xmlhttp', @obj out   exec @result = sp_oamethod @obj, 'open', null, 'get', @url, false exec @result = sp_oamethod @obj, 'setrequestheader', null, 'content-type', 'application/x-www-form-urlencoded' exec @result = sp_oamethod @obj, send, null, '' exec @result = sp_oagetproperty @obj, 'status', @httpstatus out  exec @result = sp_oagetproperty @obj, 'responsexml.xml', @response out  insert @xml ( yourxml ) exec @result = sp_oagetproperty @obj, 'responsexml.xml'--, @response out  end try begin catch set @errormsg = error_message() end catch  select  @mxml.value('(//geocoderesponse/result/formatted_address)[1]','varchar(max)')  select  yourxml.value('(//geocoderesponse/result/formatted_address)[1]','varchar(max)') @xml 

if run query null result , full result because use 2 different method.

null result :

first tried use @response varchar(8000) understand code, result obtain url larger 8000 characters, then, changed varchar(max) same error, data, , xml structure finish incomplete, giving result null when try make select.

i know can't use insert exec inside scalar function because of side-effecting operator. when use insert in table getting result.

i need function this

create function [dbo].[get_address_from_latlon]  (     @lat nvarchar(50),@lon nvarchar(50) ) returns  nvarchar(300) begin ...  

which send lat / lon , return full address

please not ask me create , run clr or ssis package ... , report can't use methods ,i need have function report.

please me this.

thanks


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -