INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Internet

Programmatically Find Latitude and Longitude by wgcs
Posted: 19 Mar 04

Do you want to find the Latitude & Longitude for a whole bunch of addresses?
 Microsoft's TerraServer provides this information as a demonstration of SqlServer and with a little VFP programming, you can make use of it from within a program.

 CDyne also provides this service, though for a fee.  It seems they allow you to try their webservice for free for about 5 minutes before locking you out.

You can use your own method of retrieving the web page, or see FAQ184-3019 for the ReadUrl function.
 

CODE

LOCAL lcSt, lcMethod, lcLong, lcLat, lcLong1, lcLat1
ON KEY LABEL ESC SUSPEND
SET DECIMALS TO 8
USE Addresses
lcMethod  = 'TERRASERVER'
*lcMethod  = 'CDYNE'

SCAN
  lcSt = UPPER( ALLTRIM(Address.hse_num)+'+'+STRTRAN(ALLTRIM(Address.Street),' ','+') )
  
  ? "Processing Record ",RECNO(),"of",RECCOUNT(), lcSt, Address.zipcode, address.State
  
  DO CASE
    CASE lcMethod='TERRASERVER'
      * You may have to log in to terraserver.microsoft.com and get a VIEWSTATE value for yourself:
      lcGetUrl = 'http://www.terraserver.microsoft.com/address.aspx?__VIEWSTATE=dDwxNzM4NTI3NTc7O2w8U2VhcmNoOz4%2B';
                 +'&Street='+lcSt;
                 +'&City=';
                 +'&State='+ALLTRIM(address.State);
                 +'&ZipCode='+ALLTRIM(address.zipcode);
                 +'&Search.x=0&Search.y=0'
                 
      ReadUrl( lcGETURL )
  
      lcLong   = SUBSTR(pineview.Resp, ATC('&lon=',pineview.Resp)+5)
      lcLong1  = LEFT( lcLong,        ATC('&',lcLong)-1 )
      
      lcLat    = SUBSTR(pineview.Resp, ATC('&lat=',pineview.Resp)+5)
      lcLat1   = LEFT( lcLat,         ATC('&',lcLat)-1 )
      REPLACE address.Longitude WITH VAL(lcLong1), ;
              address.Latitude  WITH VAL(lcLat1)
    
  CASE lcMethod='CDYNE'
    * This is a webservice that can do the same thing, only with much simpler code,
    *   and it offers about 5 minutes of free trial on license key "0" before locking you out:
    * See http://ws.cdyne.com

    lcGetUrl = "http://ws.cdyne.com/psaddress/addresslookup.asmx/AdvancedCheckAddress" ;
      +'&AddressLine='+lcSt;
      +'&AddressLine2=';
      +'&ZipCode='+ALLTRIM(address.zipcode);
      +'&City=';
      +'&StateAbbrev='+ALLTRIM(address.state);
      +'&LicenseKey=0';
      +'&Invoke=submit'
    
    ReadUrl( lcGETURL )
    lcXML = SUBSTR( bayview.resp, AT(CHR(13)+CHR(10)+CHR(13),bayview.resp)+4 )
    XMLTOCURSOR(lcXML,'Response')
    REPLACE Addresses.Longitude WITH response.AvgLongitude, ;
            Addresses.Latitude  WITH response.AvgLatitude
    lcLong1 = response.AvgLongitude
    lcLat1  = response.AvgLatitude
  ENDCASE
  
  ??" Long=",lcLong1," Lat=",lcLat1
  FLUSH
ENDSCAN

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close