WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinInet
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Latitude and Longitude of An Address

 Keywords: Latitude Longitude Address 

Question:

Does anyone have or know of a way to pass a mapping program an address (the street, city and zip), and quietly get back its latitude and longitude?

Answer:

If the end users have internet access....

Here is some code the uses Yahoo Maps Web Services to retrieve the latitude and longitude of an address:

street = '5421 California Ave SW'
city = 'Seattle'
state = 'WA'
output = 'c:\temp\result.txt'

;OUTPUT:
;<?xml version="1.0" encoding="UTF-8"?>
;<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
;xmlns="urn:yahoo:maps"
;xsi:schemaLocation="urn:yahoo:maps http://local.yahooapis.com/MapsService/V1/GeocodeResponse.xsd">
;<Result precision="address">
;    <Latitude>37.416384</Latitude>
;    <Longitude>-122.024853</Longitude>
;    <Address>5421 California Ave SW</Address>
;    <City>SEATTLE</City>
;    <State>WA</State>
;    <Zip>98116</Zip>
;    <Country>US</Country>
;  </Result>
;</ResultSet>


AddExtender("WWINT44I.DLL") ;Load Wininet Extender

street = StrReplace( street, ' ' , '+' ) ; replace spaces with plus signs
city = StrReplace( city, ' ' , '+' ) ; replace spaces with plus signs

urlrequest = `http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-cm8o18U_JX3G58_mdiv8HBgfh83jJKg-&street=` : street : `&city=` : city : `&state=`: state
tophandle = iBegin(0,'','')
datahandle = IUrlOpen(tophandle,urlrequest); standard data download of HTTP
iReadData(datahandle,output); transfers data from an internet host to a data file
iClose(datahandle) ; close handle
iClose(tophandle) ; close handle


;Parse data from output
data = FileGet( output ) ;Read data from file

;locate <latitude>
lat_beginptr = StrIndexNC( data, '<latitude>', 1, @FWDSCAN )
lat_endptr = StrIndexNC( data, '</latitude>', lat_beginptr, @FWDSCAN )
latitude = StrSub( data, lat_beginptr + StrLen('<latitude>'), lat_endptr - (lat_beginptr + StrLen('<latitude>'))  )
;Pause('latitude', latitude)

;locate <longitude>
long_beginptr = StrIndexNC( data, '<longitude>', 1, @FWDSCAN )
long_endptr = StrIndexNC( data, '</longitude>', long_beginptr, @FWDSCAN )
longitude = StrSub( data, long_beginptr + StrLen('<longitude>'), long_endptr - (long_beginptr + StrLen('<longitude>'))  )
;Pause('longitude', longitude)

str = 'Address: ' : street : ',' : city  : ',' : state : @CRLF : 'Latitude: ' : latitude : @CRLF: 'Longitude: ' : longitude

Pause( 'Where Am I?', str )
Exit

Article ID:   W17622
Filename:   Latitude and Longitude of An Address.txt
File Created: 2017:07:28:12:58:48
Last Updated: 2008:04:23:08:50:49