ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Re: GOOGLE MAPS   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

mer. 01 août 2012, 18h32
Mike Gagnon
Canada Canada

atoutfox.public.association

Re: GOOGLE MAPS

voici pour la distance entre deux adresses:


cAddress1 = "134 WILLOWBANK CR, Pointe Claire Quebec"
cAddress2 = "146 WILLOWBANK CR, Pointe Claire Quebec"

?distance(google_geo(cAddress1),google_geo(cAddress2))

PROCEDURE google_geo
LPARAMETERS tcAddress
LOCAL CRLF, cUrl, oHTTP, cKey, cResult, cTag, lTag, oIE
STORE CHR(13)+CHR(10) TO CRLF
cKey = "ABQIAAAAcRPDWjdpflEtWiz9fvI5mBQt8peg-Qi-HdXYFgx7vW0gS1KrCRRzSUUHdn8n7fvGjm47XE8D1P3Dvw"


SET LIBRARY TO Home()+"Foxtools.fll" ADDITIVE
tcAddress = CHRTRAN(ALLTRIM(reduce(tcAddress)),CHR(32), "+")

cURL = "http://maps.google.com/maps/geo?q="; + tcAddress + "&output=csv&key=" + cKey

oHTTP = CreateObject("MSXML2.XMLHTTP")
oHTTP.Open("GET", cURL, .f.)
oHTTP.Send
cResult=(oHTTP.ResponseText)

nCode=GETWORDNUM(cResult,1,",")
nAccuracy=GETWORDNUM(cResult,2,",")
nLat=GETWORDNUM(cResult,3,",")
nLon=GETWORDNUM(cResult,4,",")

STRTOFILE(cResult,'cut.txt')
RETURN nLon + "," + nLat + "," + nCode + "," + nAccuracy
ENDIF

*!* CODE
*!* G_GEO_SUCCESS (200)
*!* No errors occurred; the address was successfully parsed and its geocode has been returned. (Since 2.55)

*!* G_GEO_SERVER_ERROR (500)
*!* A geocoding request could not be successfully processed, yet the exact reason for the failure is not known. (Since 2.55)

*!* G_GEO_MISSING_ADDRESS (601)
*!* The HTTP q parameter was either missing or had no value. (Since 2.55)

*!* G_GEO_UNKNOWN_ADDRESS (602)
*!* No corresponding geographic location could be found for the specified address. This may be due to the fact that the address is relatively new, or it may be incorrect. (Since 2.55)

*!* G_UNAVAILABLE_ADDRESS (603)
*!* The geocode for the given address cannot be returned due to legal or contractual reasons. (Since 2.55)


*!* G_GEO_BAD_KEY (610)
*!* The given key is either invalid or does not match the domain for which it was given. (Since 2.55)

*!* Accuracy
*!* 0 Unknown location. (Since 2.59)
*!* 1 Country level accuracy. (Since 2.59)
*!* 2 Region (state, province, prefecture, etc.) level accuracy. (Since 2.59)
*!* 3 Sub-region (county, municipality, etc.) level accuracy. (Since 2.59)
*!* 4 Town (city, village) level accuracy. (Since 2.59)
*!* 5 Post code (zip code) level accuracy. (Since 2.59)
*!* 6 Street level accuracy. (Since 2.59)
*!* 7 Intersection level accuracy. (Since 2.59)
*!* 8 Address level accuracy. (Since 2.59)

ENDPROC

PROCEDURE distance
LPARAMETERS tcGeo1, tcGeo2

lnLon1 = VAL(GETWORDNUM(tcGeo1,1,","))
lnLat1 = VAL(GETWORDNUM(tcGeo1,2,","))
lnLon2 = VAL(GETWORDNUM(tcGeo2,1,","))
lnLat2 = VAL(GETWORDNUM(tcGeo2,2,","))

lnDistance = 3963.000000*ACOS(COS(DTOR(90-lnLat1))*COS(DTOR(90-lnLat2))+;
SIN(DTOR(90-lnLat1))*SIN(DTOR(90-lnLat2))*COS(DTOR(lnLon1 - lnLon2)))

IF lnDistance < .25
lcDistance = TRANSFORM(ROUND(lnDistance*5280,2)) +" feet"
ELSE
lcDistance = TRANSFORM(ROUND(lnDistance,2)) + " miles"
ENDIF

RETURN lcDistance
ENDPROC

Permalink : http://www.atoutfox.org/nntp.asp?ID=0000009500
20 286 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2026.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3