How can I fetch Google static maps with TIdHTTP?

Posted by cloudstrif3 on Stack Overflow See other posts from Stack Overflow or by cloudstrif3
Published on 2010-04-23T04:33:34Z Indexed on 2010/04/27 17:13 UTC
Read the original article Hit count: 338

Filed under:
|
|

I'm trying to return content from maps.google.com from within Delphi 2006 using the TIdHTTP component.

My code is as follows

procedure TForm1.GetGoogleMap();
var
  t_GetRequest: String;
  t_Source: TStringList;
  t_Stream: TMemoryStream;
begin
  t_Source := TStringList.Create;

  try
    t_Stream := TMemoryStream.Create;

    try
      t_GetRequest :=
        'http://maps.google.com/maps/api/staticmap?' +
        'center=Brooklyn+Bridge,New+York,NY' +
        '&zoom=14' +
        '&size=512x512' +
        '&maptype=roadmap' +
        '&markers=color:blue|label:S|40.702147,-74.015794' +
        '&markers=color:green|label:G|40.711614,-74.012318' +
        '&markers=color:red|color:red|label:C|40.718217,-73.998284' +
        '&sensor=false';

      IdHTTP1.Post(t_GetRequest, t_Source, t_Stream);

      t_Stream.SaveToFile('google.html');
    finally
      t_Stream.Free;
    end;
  finally
    t_Source.Free;
  end;
end;

However I keep getting the response HTTP/1.0 403 Forbidden. I assume this means that I don't have permission to make this request but if I copy the url into my web browser IE 8, it works fine. Is there some header information that I need or something else?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about google