Bepaal de geo coordinaten in openedge via google maps

/* get geo code via google maps */

USING System.Net.*.
USING Progress.Json.ObjectModel.*.


def var cLong as char no-undo.
def var cLat as char no-undo.
def var cAdres as char no-undo init "europlaan 22+amsterdam+nl". /* RAI amsterdam */

run ip_getgeocode( input cAdres, output cLat, Output cLong ).

message cLat cLong view-as alert-box.
  

procedure ip_getgeocode:
  def  input parameter cAddress as char no-undo.
  def  output parameter dLat    as dec no-undo.
  def  output parameter dLong   as dec no-undo.
  
  def var cDownload    as longchar   no-undo .
  def var geoArray     as JsonArray  no-undo.
  def var jsonMessage  as JsonObject no-undo.
  def var jsonlocation as jsonobject no-undo.
  
  def var cUrl as char no-undo.   
  def var cTmp as char no-undo.
  
  def var oWebClient as CLASS WebClient no-undo.
  def var oJsonParser as ObjectModelParser no-undo.
  
  
  oWebClient = new Webclient().
  oJsonParser = new ObjectModelParser( ).
    
   /*owebClient:Headers:Add("CharSet", "UTF-8"). */
  owebClient:Headers:Add("Charset", "text/html; charset=UTF-8").
  oWebclient:Headers:Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" ).

  
  cUrl = 'http://maps.googleapis.com/maps/api/geocode/json?address='
     + replace( cAddress, ' ', '%20' ) + '&sensor=false'.
  cDownload = oWebclient:DownloadString (cUrl) no-error.
  if error-status:error
  then run ip_loggooglemapserror(  cUrl + ' ' + ERROR-STATUS:GET-MESSAGE(1) ).
  else copy-lob from cDownload to file ( session:temp-directory + 'lastgeocode.json') no-convert no-error.
  
  JsonMessage = CAST(oJsonParser:Parse(cDownload), JsonObject).
  geoArray = jsonmessage:GETJSONARRAY("results").
  


  if geoarray:Length >= 1
  then do:
    jsonMESSAGE = geoarray:GETJSONOBJECT(1).
    if jsonMESSAGE:has( "geometry" ) 
    then do:
      if jsonMESSAGE:GetJsonObject( "geometry" ):has( "location" ) 
      then do:
        cTmp = session:numeric-format.
        session:numeric-format = 'American'.
        
        jsonlocation = jsonMESSAGE:GetJsonObject( "geometry" ):getJsonObject( "location" ).
        dLat  = jsonlocation:GetDecimal("lat") .
        dLong = jsonlocation:GetDecimal("lng" ).
        
        session:numeric-format = cTmp.        
      end.
    end.
  end.
  
  delete object oWebClient.
  delete object oJsonParser.
end.