Hi Seán,
this is a our program that we use to get the coordinate from an address.
To use it need to add the LIBHTTP program from Scott Klement
And you must put your Google Key where is the xxxxxxxxxxxxxxxxxx character
I hope can help you
Fabio
H DFTACTGRP(*NO) BNDDIR('LIBHTTP/HTTPAPIR4')
**********************************************************************
** Scopo del programma: Recuperare via web services le coordinate *
** gps dato u dindirizzo. *
** Nota bene: L'indirizzo deve essere così composto: *
** via+cap+localita+provincia+nazione *
** P.es: 'Via pinco 11+20063+cernusco sul naviglio+mi+it *
** Rende le coordinate se trovate altrimenti sono zero. *
** *
** N.b: Il web service rende anche le informazioni dell'accuratezza *
** della ricerca eseguita nonchè l'indirizzo "interpretato" dal *
** web services. *
** Risposta del web services campo status: *
** "OK" Indicates that no errors occurred. *
** the address was successfully parsed and at least one *
** geocode was returned. *
** *
** "ZERO_RESULTS" Indicates that the geocode was successful but *
** returned no results. This may occur if the *
** geocoder was passed a non-existent address. *
** *
** "OVER_QUERY_LIMIT" Indicates that you are over your quota. *
** *
** "REQUEST_DENIED" Indicates that your request was denied. *
** *
** "INVALID_REQUEST" Generally indicates that the query *
** (address, components or latlng) is missing.*
** *
** "UNKNOWN_ERROR" Indicates that the request could not be *
** processed due to a server error. *
** The request may succeed if you try again. *
** *
/include LIBHTTP/QRPGLESRC,httpapi_h
/include LIBHTTP/QRPGLESRC,ifsio_h
D ParametriRic PR ExtPgm('GXCOSA1R')
D Indirizzo 200a
D Latitudine 9 6
D Longitudine 9 6
D ParametriRic PI
D Indirizzo 200a
D Latitudine 9 6
D Longitudine 9 6
D QCMDEXEC PR ExtPgm('QCMDEXC')
D command 32702a const options(*varsize)
D len 15p 5 const
D igc 3a const options(*nopass)
D GoogleResponse PR
D r likeds(resp)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 65535A varying const
D Attrs * dim(32767)
D const options(*varsize)
* google - Geocoding Request fields:
D req DS qualified inz
D address 150a varying
D sensor 5a varying
D key 100a varying
* google - Geocoding Response fields:
D resp DS qualified inz
D Latitude 9p 6
D Longitude 9p 6
D Address 50a varying
D status 256a varying
D Tipo 256a varying
D Enc s like(HTTP_URL_ENCODER)
D url s 32767a varying
D filename s 50A varying
D cmd s 200A
D msg s 52A
D wait s 1A
D rc s 10I 0
D postData s *
D postDataSize s 10I 0
D x s 10I 0
D agent s 64a
*Inlr = *On;
Monitor;
Cmd = 'ADDLIBLE LIB(LIBHTTP) POSITION(*LAST)';
QCMDEXEC(Cmd: %Len(%Trim(Cmd)));
on-error;
endmon;
Latitudine = 0;
Longitudine = 0;
req.address = %Trim(Indirizzo);
req.sensor = 'false';
req.key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
Enc = http_url_encoder_new();
http_url_encoder_addvar_s( enc: 'address' : req.address );
http_url_encoder_addvar_s( enc: 'sensor' : req.sensor );
http_url_encoder_addvar_s( enc: 'key' : req.key );
url = '
https://maps.googleapis.com/maps/api/geocode/xml?'
+ http_url_encoder_getstr(enc);
http_url_encoder_free(enc);
http_debug(*ON);
filename = http_tempfile() + '.xml';
rc = http_url_get( url : filename );
if (rc < 1);
unlink(filename);
http_crash();
return;
endif;
// ****************************************************
// parse the XML from the temp file.
// ****************************************************
Clear Resp;
rc =http_parse_xml_stmf( filename
: HTTP_XML_CALC
: *null
: %paddr(GoogleResponse)
: %addr(resp) );
unlink(filename);
if (rc < 0);
http_crash();
return;
endif;
// ****************************************************
// Print the news headlines & links to the full
// articles
//
// Note: If you wanted to, you could retrieve the
// articles themselves by calling http_url_get
// for each link.
// ****************************************************
if (resp.status <> 'OK');
http_comp(resp.status);
return;
endif;
If (Resp.Tipo <> *Blank);
endif;
//dsply (' Lat = ' + %char(resp.Latitude) );
//dsply (' Lon = ' + %char(resp.Longitude) );
//dsply ('Press <ENTER> to continue') ' ' wait;
Latitudine = resp.Latitude;
Longitudine = resp.Longitude;
return;
P GoogleResponse B
D GoogleResponse PI
D r likeds(resp)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 65535A varying const
D attrs * dim(32767)
D const options(*varsize)
if ( path = '/GeocodeResponse' );
if name = 'status';
r.status = %trimr(value);
endif;
endif;
if ( path = '/GeocodeResponse/result/geometry/location');
select;
when name = 'lat' and r.latitude = 0;
r.latitude = %dec(value:9:6);
when name = 'lng' and r.longitude = 0;
r.longitude = %dec(value:9:6);
endsl;
endif;
if ( path = '/GeocodeResponse/result' );
if name = 'formatted_address';
r.address = %trimr(value);
endif;
endif;
if ( path = '/GeocodeResponse/result/geometry/location_type');
r.Tipo = %trimr(value);
endif;
P E
-----Messaggio originale-----
Da: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> Per conto di Sean Courtney
Inviato: mercoledì 19 ottobre 2022 12:21
A: rpg400-l@xxxxxxxxxxxxxxxxxx
Oggetto: GPS coordinates
Priorità: Alta
Hello All,
has anybody got a more or less working example of using googles geo API to return the geo coordinates of a given address.
Preferably using SQL but I will take anything I get.
Thanks in advance .
Mit freundlichen Grüßen / Kind regards / Bien à vous,
Seán Courtney
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.