Das Thema ist hier ja schon reichlich betagt, aber eventuell doch noch a jour.
Horst
Klasse für Geokoordinaten --- EIgenen Proxy einsetzen
*----------------------------------------------------------------------*
* CLASS cl_geokoordinate DEFINITION
*----------------------------------------------------------------------
class cl_geokoordinate definition inheriting from ztabproxy.
*
public section.
**** System
*
class-methods class_constructor.
*
methods : constructor.
**** Offene
*
types: begin of ty_table,
postlz type pstlz,
ort type ort01_gp,
strass type stras_gp,
hnumm type text10,
long(9) type c,
lat(9) type c,
end of ty_table.
*
methods : get_koordinate importing p_postlz type pstlz
p_ort type ort01_gp
p_strass type stras_gp
p_hnumm type text10 optional
exporting p_result type ty_table
p_error like sy-subrc.
*
methods : free redefinition.
**** Privat
*
private section.
constants : my_proxy type proxy value 'xxxx', " Eigenen Proxy einsetzen
spacer(3) type c value '%20'.
types : begin of gs_line,
line(132) type c,
end of gs_line.
types : begin of ty_xml,
data(256) type x,
end of ty_xml.
types ty_xmltab type standard table of ty_xml.
types : begin of ty_res,
indent type i,
element(64) type c,
attribute(64) type c,
value(512) type c,
end of ty_res.
data : ta_result type table of ty_res,
wa_result type ty_res.
data : itab_xml type ty_xmltab, " Tabelle
istr_xml type ty_xml, " Struktur
xml_table_size type i.
data : my_url(512) type c,
s(512) type c.
data : ansii_string type string,
ansii_lang type i,
posi type i,
char(1) type c.
* Interne Tabellen
data : ta_table type hashed table of ty_table
with unique key postlz ort strass hnumm,
wa_table type ty_table.
data : my_header type table of gs_line,
my_body_table type table of gs_line,
my_body_line type gs_line.
*
methods : set_proxy importing proxy_postlz type pstlz
proxy_ort type ort01_gp
proxy_strass type stras_gp
proxy_hnumm type text10
exporting proxy_result type ty_table
proxy_error like sy-subrc.
*
methods : get_proxy importing proxy_postlz type pstlz
proxy_ort type ort01_gp
proxy_strass type stras_gp
proxy_hnumm type text10
exporting proxy_result type ty_table
proxy_error like sy-subrc.
*
methods : greate_xml importing proxy_string type string
exporting proxy_tab type ty_xmltab.
*
methods : kill_one.
*
endclass. "cl_GEOKOORDINATE DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_geokoordinate IMPLEMENTATION
*----------------------------------------------------------------------*
class cl_geokoordinate implementation.
**** System
method class_constructor.
endmethod. "class_constructor
*
method constructor.
call method super->constructor.
s = '
http://local.yahooapis.com/MapsService/ ... appid=test'.
refresh ta_table.
clear wa_table.
endmethod. "constructor
**** Privat
*
method kill_one.
clear wa_table.
loop at ta_table into wa_table.
exit.
endloop.
delete table ta_table from wa_table.
endmethod. "kill_one
*
method greate_xml.
data : short(256) type c.
field-symbols: <fs> type any.
ansii_lang = strlen( proxy_string ).
while ansii_lang > 256.
short = ansii_string+0(256).
assign short to <fs> casting type x.
istr_xml-data = <fs>.
shift ansii_string left by 256 places.
append istr_xml to proxy_tab.
ansii_lang = strlen( ansii_string ).
endwhile.
if ansii_lang > 0.
clear short.
clear istr_xml.
short = ansii_string+0(ansii_lang).
assign short to <fs> casting type x.
istr_xml-data = <fs>.
append istr_xml to proxy_tab.
endif.
clear ansii_string.
endmethod. "greate_xml
*
method set_proxy.
define formatter.
translate &1 to upper case.
replace all occurrences of 'Ä' in &1 with 'AE'.
replace all occurrences of 'ä' in &1 with 'AE'.
replace all occurrences of 'Ö' in &1 with 'OE'.
replace all occurrences of 'ö' in &1 with 'OE'.
replace all occurrences of 'Ü' in &1 with 'UE'.
replace all occurrences of 'ü' in &1 with 'UE'.
replace all occurrences of 'ß' in &1 with 'SS'.
condense &1.
end-of-definition.
define filler.
condense &1.
ansii_string = &1.
ansii_lang = strlen( ansii_string ).
clear &1.
do ansii_lang times.
char = ansii_string+0(1).
shift ansii_string left by 1 places.
concatenate &1 char into &1.
if char = space.
concatenate &1 spacer into &1.
endif.
enddo.
end-of-definition.
define read_value.
read table ta_result with key element = &1 into wa_result.
proxy_error = sy-subrc.
if proxy_error <> 0.
exit.
endif..
end-of-definition.
data : city type ort01_gp,
street type stras_gp.
clear : wa_table, my_body_table, itab_xml.
city = proxy_ort.
street = proxy_strass.
formatter city. "#EC TRANSLANG
filler city.
formatter street. "#EC TRANSLANG
replace all occurrences of 'STR.' in street with ''.
replace all occurrences of 'STRASSE' in street with ''.
filler street.
concatenate s '&street=' street spacer proxy_hnumm into my_url.
concatenate my_url '&city=' city into my_url.
concatenate my_url '&zip=' proxy_postlz into my_url.
call function 'HTTP_GET'
exporting
absolute_uri = my_url
* REQUEST_ENTITY_BODY_LENGTH =
* RFC_DESTINATION =
proxy = my_proxy
* PROXY_USER =
* PROXY_PASSWORD =
* USER =
* PASSWORD =
* BLANKSTOCRLF =
timeout = '10'
* IMPORTING
* STATUS_CODE =
* STATUS_TEXT =
* RESPONSE_ENTITY_BODY_LENGTH =
tables
* REQUEST_ENTITY_BODY =
response_entity_body = my_body_table
response_headers = my_header
* REQUEST_HEADERS =
exceptions
connect_failed = 1
timeout = 2
internal_error = 3
tcpip_error = 4
data_error = 5
system_failure = 6
communication_failure = 7
others = 8.
proxy_error = sy-subrc.
if proxy_error = 0.
clear ansii_string.
loop at my_body_table into my_body_line.
concatenate ansii_string my_body_line-line into ansii_string.
endloop.
ansii_lang = strlen( ansii_string ).
xml_table_size = ansii_lang + 2.
call method me->greate_xml
exporting
proxy_string = ansii_string
importing
proxy_tab = itab_xml.
data o_xmlparser type ref to cl_xmlparser.
if o_xmlparser is initial.
create object o_xmlparser.
endif.
call method o_xmlparser->simpel_parse
exporting
p_table = itab_xml
p_lang = xml_table_size
importing
p_tab = ta_result
p_error = proxy_error.
if proxy_error is initial.
wa_table-postlz = proxy_postlz.
wa_table-ort = proxy_ort.
wa_table-strass = proxy_strass.
wa_table-hnumm = proxy_hnumm.
read_value 'LATITUDE'. wa_table-lat = wa_result-value.
read_value 'LONGITUDE'. wa_table-long = wa_result-value.
insert wa_table into table ta_table.
endif.
endif.
proxy_result = wa_table.
endmethod. "set_proxy
*
method get_proxy.
read table ta_table
with table key postlz = proxy_postlz
ort = proxy_ort
strass = proxy_strass
hnumm = proxy_hnumm
into proxy_result.
proxy_error = sy-subrc.
endmethod. "get_proxy
**** Offene
*
method free.
call method super->free.
free ta_table.
clear : wa_table.
endmethod. "free
*
method get_koordinate.
clear p_error.
gesamt = gesamt + 1.
get run time field start.
call method me->get_proxy
exporting
proxy_postlz = p_postlz
proxy_ort = p_ort
proxy_strass = p_strass
proxy_hnumm = p_hnumm
importing
proxy_result = wa_table
proxy_error = notfound.
get run time field ende.
if not notfound is initial.
get run time field start.
call method me->set_proxy
exporting
proxy_postlz = p_postlz
proxy_ort = p_ort
proxy_strass = p_strass
proxy_hnumm = p_hnumm
importing
proxy_result = wa_table
proxy_error = p_error.
get run time field ende.
zeitlesen = ende - start.
anzahl = anzahl + 1.
else.
zeitproxy = ende - start.
treffer = treffer + 1.
endif.
p_result = wa_table.
if anzahl > maxanzahl.
call method me->kill_one.
anzahl = anzahl - 1.
endif.
endmethod. "get_koordinate
*
endclass. "cl_geokoordinate IMPLEMENTATION
*
und aus zwei dieser Punkte die Distanz ermitteln
*Umrechnung der Grad-, Minuten und Sekunden in eine Kommazahl:
*
*Breite Frankfurt: 50 + (06 / 60) + (44 / 3600) = 50,11222°
*Länge Frankfurt: 08 + (40 / 60) + (55 / 3600) = 08,68194°
*Breite Berlin...: 52 + (31 / 60) + (20 / 3600) = 52,52222°
*Länge Berlin...: 13 + (17 / 60) + (51 / 3600) = 13,29750°
*----------------------------------------------------------------------*
* CLASS cl_geodistanz DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class cl_geodistanz definition.
public section.
types : ty_geowert(16) type p decimals 9,
ty_km(10) type p decimals 2.
data : start_latitude type ty_geowert,
start_longitude type ty_geowert,
ziel_latitude type ty_geowert,
ziel_longitude type ty_geowert.
data : km type ty_km.
methods get_distanz importing start_latitude type ty_geowert
start_longitude type ty_geowert
ziel_latitude type ty_geowert
ziel_longitude type ty_geowert
returning value(km) type ty_km.
private section.
constants : erdradius type f value '6378.137',
pi type f value '3.1415926535'.
data : rad_breite_1 type f, " Start Latitude
rad_breite_2 type f, " Ziel Latitude
rad_laenge_1 type f,
rad_laenge_2 type f.
data : delta1 type f,
delta2 type f,
delta3 type f.
endclass. "cl_geodistanz DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_geodistanz IMPLEMEANTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class cl_geodistanz implementation.
method get_distanz.
rad_breite_1 = start_latitude / 180 * pi.
rad_breite_2 = ziel_latitude / 180 * pi.
rad_laenge_1 = start_longitude / 180 * pi.
rad_laenge_2 = ziel_longitude / 180 * pi.
delta1 = sin( rad_breite_1 ) * sin( rad_breite_2 ).
delta2 = cos( rad_breite_1 ) * cos( rad_breite_2 ).
delta3 = cos( rad_laenge_2 - rad_laenge_1 ).
km = acos( delta1 + delta2 * delta3 ) * erdradius.
endmethod. "get_distanz
endclass. "cl_geodistanz IMPLEMANTATION