× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.