You need to URLEncode Edit_str.Text etc. before adding it to the URL.
Not sure if there is a ready made URLEncode in Lazarus/FPC
TIdHTTP is an Indy component. Indy also has a TIdURI class for dealing with URL encodings.
Also, TIdHTTP.Get() raises an exception if the HTTP request fails. The original code did not take that into account, so the json string would be empty if Get() failed, causing GetJSON() to also fail and raise its own exception.
Also, FindPath() returns nil if the requested value is not found. The original code did not take that into account, either. Use GetPath() instead, and let it raise its own exception if the requested value is not found.
Try this instead:
procedure Tfrm_maps.geocoding(Sender: TObject);
var
RequestURL: string;
jData, jLocation : TJSONData;
json, status: string;
begin
if Edit_str.GetTextLen = 0 then Exit;
RequestURL := 'https://maps.googleapis.com/maps/api/geocode/json?address=' + TIdURI.ParamsEncode(Edit_str.Text) + ',+' + TIdURI.ParamsEncode(Edit_city.Text) + '+' + TIdURI.ParamsEncode(Edit_plz.Text) + '&key=' + TIdURI.ParamsEncode(var_g_api_key);
// or:
// RequestURL := 'https://maps.googleapis.com/maps/api/geocode/json?address=' + TIdURI.ParamsEncode(Edit_str.Text + ', ' + Edit_city.Text + ' ' + Edit_plz.Text) + '&key=' + TIdURI.ParamsEncode(var_g_api_key);
try
json := IdHTTP1.Get(RequestURL);
jData := GetJSON(json);
status := jData.GetPath('status').AsString;
if status <> 'OK' then
begin
ShowMessage('Google Error happened: ' + status);
end
else
begin
jLocation := jData.GetPath('results[0].geometry.location');
var_gps_lat := FloatToStrF(jLocation.GetPath('lat').AsFloat, ffGeneral, 20, 15);
var_gps_lng := FloatToStrF(jLocation.GetPath('lng').AsFloat, ffGeneral, 20, 15);
end;
except
on E: EIdHTTPProtocolException do begin
ShowMessage('HTTP Error happened: ' + E.Message);
end;
on E: Exception do begin
ShowMessage('Unknown Error happened: ' + E.Message);
end;
end;
end;