• Allen McGuire (6/26/2008)


    I personally would not use this method to do what you are trying to do. If you have a web server that can run ASP, I would simply make a database call to get the customers and their address data, then call the following function with as much or little address information as you wish:

    Function GetGoogleCoordsCSV(Query)

    GoogleMapKey = "your Google key"

    url = "http://maps.google.com/maps/geo?output=csv&key=" & GoogleMapKey & "&q=" & Replace(Query,"#","")

    set csvhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

    csvhttp.open "GET", url, false

    csvhttp.send ""

    csvResult = Split(csvhttp.responseText, ",")

    ' The first number is the status code,

    ' the second is the accuracy,

    ' the third is the latitude,

    ' the fourth one is the longitude.

    ' 0 Unknown location.

    ' 1 Country level accuracy.

    ' 2 Region (state, province, prefecture, etc.) level accuracy.

    ' 3 Sub-region (county, municipality, etc.) level accuracy.

    ' 4 Town (city, village) level accuracy.

    ' 5 Post code (zip code) level accuracy.

    ' 6 Street level accuracy.

    ' 7 Intersection level accuracy.

    ' 8 Address level accuracy.

    Precision = csvResult(1)

    Longitude = csvResult(3)

    Latitude = csvResult(2)

    End Function

    Then just run an update statement in the ASP to update the customer coordinates. If you need more information let me know. Here is the code for the main ASP page:

    <%

    strSQL = "SELECT CustomerID, Address1, City, State, Zip FROM Customer"

    Set oRs = oConn.Execute(strSQL)

    Do While Not oRs.EOF

    CustomerID = orS("CustomerID")

    Address1 = oRs("Address1")

    City = oRs("City")

    State = oRs("State")

    Zip = oRs("Zip")

    If Address1 <> "" and City <> "" Then ' no sense in geocoding blank address

    Call GetGoogleCoordsCSV(Replace(Address1,"#","") & " " & City & " " & State)

    oConn.Execute("UPDATE Customer SET Latitude = '" & Latitude & "', Longitude = '" & Longitude & "', Modified = GETDATE() WHERE CustomerID = " & CustomerID & "")

    End If

    oRs.MoveNext

    Loop

    %>

    thanks for the code! works great! is it possible to do the same in aspx, c#? i'm not really familiar with .net.