Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GoogleMap-plot more than 2 points?
Message
General information
Forum:
Visual FoxPro
Category:
Third party products
Environment versions
Visual FoxPro:
VFP 9
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01351666
Message ID:
01351736
Views:
28
This message has been marked as the solution to the initial question of the thread.
>Great! Thanks. But how do you get the longitude/latidudes to plot if all you have is addresses???
>Are you going to go to SWFox again this year?
>
>Peter

Here's a much improved version of the code, now that I've had a moment to think about it and rewrite the original proof-of-concept...
LOCAL lcAddress, lcLongitude, lcLatitude
m.lcAddress = "7651 209th Street North,Forest Lake,MN"
GetLongLatFromAddress(m.lcAddress, @m.lcLongitude, @m.lcLatitude)
MESSAGEBOX("Longitude: " + m.lcLongitude + CHR(13) + "Latitude: " + m.lcLatitude, 64, "Geo Information")

************************
FUNCTION GetLongLatFromAddress(tcAddress, tcLongitude, tcLatitude)
************************
LOCAL lcAddress, lcURL, loXMLHTTP as MSXML2.XMLHTTP, lcReturn
m.loXMLHTTP = CreateObject("MSXML2.XMLHTTP")
m.lcAddress = UrlEncode(m.tcAddress, .F.)
m.lcAddress = HandleUnsafeChars(m.lcAddress)
m.lcURL = "http://rpc.geocoder.us/service/rest?address=" + m.lcAddress
m.loXMLHTTP.open("GET", m.lcURL, .F.) && third parameter needed to avoid need to check readyState
m.loXMLHTTP.send()
m.lcReturn = m.loXMLHTTP.responseText
m.tcLongitude = STREXTRACT(m.lcReturn,"<geo:long>", "</geo:long>",1,1)
m.tcLatitude = STREXTRACT(m.lcReturn,"<geo:lat>", "</geo:lat>",1,1)
RETURN m.lcReturn
ENDFUNC

************************
FUNCTION UrlEncode(tcString, tlNoPlus)
	************************
	LOCAL lcReturn, lcChar, lnCounter
	m.lcReturn=""
	FOR m.lnCounter = 1 TO LEN(m.tcString)
		m.lcChar = SUBSTR(m.tcString, m.lnCounter, 1)
		IF ATC(m.lcChar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") > 0
			m.lcReturn = m.lcReturn + m.lcChar
			LOOP
		ENDIF
		IF ASC(m.lcChar) = 32 AND !m.tlNoPlus
			m.lcReturn = m.lcReturn + "+"
			LOOP
		ENDIF
		m.lcReturn = m.lcReturn + "%" + RIGHT(TRANSFORM(ASC(m.lcChar),"@0"),2)
	ENDFOR
	RETURN m.lcReturn
ENDFUNC

************************
FUNCTION HandleUnsafeChars(tcString)
	************************
	LOCAL lcReturn, lcBuffer, lnBufferSize
	#DEFINE ICU_BROWSER_MODE 0x2000000
	DECLARE INTEGER InternetCanonicalizeUrl IN wininet;
		STRING sURL, STRING @sBUFFER, INTEGER @nLength, INTEGER nFlags
	m.lnBufferSize = 250
	m.lcBuffer = REPLICATE(CHR(0), m.lnBufferSize)
	IF InternetCanonicalizeUrl (m.tcString, @m.lcBuffer, @m.lnBufferSize, ICU_BROWSER_MODE) != 0
		m.lcReturn = LEFT(m.lcBuffer, m.lnBufferSize)
	ELSE
		m.lcReturn = ""
	ENDIF
	RETURN m.lcReturn
ENDFUNC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform