PROGRAM _INIT
RequestHeader.protocol := 'HTTP/1.1';
RequestHeader.contentType := 'text/html';
RequestHeader.contentLength := 0;
RequestHeader.connection := 'Close';
RequestHeader.keepAlive := 'timeout=5, max=100';
RequestHeader.userLine[0].name := 'User-agent';
RequestHeader.userLine[0].value := 'BuR Client';
RequestHeader.host := 'localhost';
Client.method := httpMETHOD_GET;
Client.option := httpOPTION_HTTP_11;
Client.pHost := ADR('nominatim.openstreetmap.org');
Client.pUri := ADR('search?q=Schanzenstrasse%2090,8500%20Hamburg&format=json&limit=1');
Client.pRequestHeader := ADR(RequestHeader);
Client.hostPort := 443;
Client.pResponseData := ADR(jsonString);
Client.responseDataSize := SIZEOF(jsonString);
END_PROGRAM
PROGRAM _CYCLIC
Client(enable := TRUE); (* Call httpClient() *)
IF Client.status <> 0 THEN
Client.send := FALSE;
END_IF
IF Client.httpStatus = 200 THEN
// place_id
posStart := FIND(IN1 := jsonString, IN2 := '"place_id":') + LEN('"place_id":');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := ',');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.place_id := STRING_TO_UDINT(tempStr);
// licence
posStart := FIND(IN1 := jsonString, IN2 := '"licence":"') + LEN('"licence":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
PlaceData.licence := MID(restStr, posEnd - 1, 1);
// osm_type
posStart := FIND(IN1 := jsonString, IN2 := '"osm_type":"') + LEN('"osm_type":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
PlaceData.osm_type := MID(restStr, posEnd - 1, 1);
// osm_id
posStart := FIND(IN1 := jsonString, IN2 := '"osm_id":') + LEN('"osm_id":');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := ',');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.osm_id := STRING_TO_UDINT(tempStr);
// lat
posStart := FIND(IN1 := jsonString, IN2 := '"lat":"') + LEN('"lat":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.lat := STRING_TO_REAL(tempStr);
// lon
posStart := FIND(IN1 := jsonString, IN2 := '"lon":"') + LEN('"lon":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.lon := STRING_TO_REAL(tempStr);
// class
posStart := FIND(IN1 := jsonString, IN2 := '"class":"') + LEN('"class":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
PlaceData.class := MID(restStr, posEnd - 1, 1);
// type
posStart := FIND(IN1 := jsonString, IN2 := '"type":"') + LEN('"type":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
PlaceData.type := MID(restStr, posEnd - 1, 1);
// place_rank
posStart := FIND(IN1 := jsonString, IN2 := '"place_rank":') + LEN('"place_rank":');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := ',');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.place_rank := STRING_TO_INT(tempStr);
// importance
posStart := FIND(IN1 := jsonString, IN2 := '"importance":') + LEN('"importance":');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := ',');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.importance := STRING_TO_REAL(tempStr);
// addresstype
posStart := FIND(IN1 := jsonString, IN2 := '"addresstype":"') + LEN('"addresstype":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
PlaceData.addresstype := MID(restStr, posEnd - 1, 1);
// name
posStart := FIND(IN1 := jsonString, IN2 := '"name":"') + LEN('"name":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
PlaceData.name := MID(restStr, posEnd - 1, 1);
// display_name
posStart := FIND(IN1 := jsonString, IN2 := '"display_name":"') + LEN('"display_name":"');
restStr := MID(jsonString, LEN(jsonString), posStart);
posEnd := FIND(IN1 := restStr, IN2 := '"');
PlaceData.display_name := MID(restStr, posEnd - 1, 1);
// boundingbox[1] bis [4]
posStart := FIND(IN1 := jsonString, IN2 := '"boundingbox":["') + LEN('"boundingbox":["');
restStr := MID(jsonString, LEN(jsonString), posStart);
// boundingbox[1]
posEnd := FIND(IN1 := restStr, IN2 := '"');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.boundingbox[1] := STRING_TO_REAL(tempStr);
// boundingbox[2]
restStr := MID(restStr, LEN(restStr), posEnd + 2);
posEnd := FIND(IN1 := restStr, IN2 := '"');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.boundingbox[2] := STRING_TO_REAL(tempStr);
// boundingbox[3]
restStr := MID(restStr, LEN(restStr), posEnd + 2);
posEnd := FIND(IN1 := restStr, IN2 := '"');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.boundingbox[3] := STRING_TO_REAL(tempStr);
// boundingbox[4]
restStr := MID(restStr, LEN(restStr), posEnd + 2);
posEnd := FIND(IN1 := restStr, IN2 := '"');
tempStr := MID(restStr, posEnd - 1, 1);
PlaceData.boundingbox[4] := STRING_TO_REAL(tempStr);
ELSE
// GGF. FEHLERBEHANDLUNG
END_IF
END_PROGRAM
PROGRAM _EXIT
(* Release Client instance *)
Client(enable := 0, send := 0);
END_PROGRAM