7

I need to be able to access the Google Maps API from a non-web application. I see in Google Maps' FAQs that this is possible. However, I cannot find any reference to accessing the API from a PC-based application. Can someone point me in the right direction?

(I want to access the API from a Delphi application, if that helps.)

Thanks in advance.

Kara
  • 6,115
  • 16
  • 50
  • 57
rickstep
  • 71
  • 1
  • 1
  • 4
  • 1
    Before you spend more time on writing code, you should read the license terms very carefully and maybe consider using OpenStreetMap instead. Just saying... – dummzeuch Jun 01 '12 at 07:04
  • My bottom line is that I need to capture a route on which a person drives, from start to stop. I need the street name, city, and state/province. Supposedly, the Google Maps API has a geodecoder which would give me that information, knowing the GPS coordinates. – rickstep Jun 01 '12 at 14:01
  • It appears that nominatim from OpenStreetMap contains the data that I am looking for. Since I am a newbie at this, are there any examples of how to call nomiatim from within Delphi and interpret the xml results? – rickstep Jun 11 '12 at 18:45

3 Answers3

15

Some time ago I wrote a series of articles about using the Google maps API v3 from Delphi, basically you need a TWebBrowser component and load an HTML page with the JavaScript code to handle the Google Maps JavaScript API v3. from here using functions like IHTMLWindow2.execScript and the MSHTML Interfaces you can interact with the JavaScript code and the Google Maps API responses from Delphi.

Also take a look to these projects

BenMorel
  • 34,448
  • 50
  • 182
  • 322
RRUZ
  • 134,889
  • 20
  • 356
  • 483
5

If you have serious plans in this direction:
Forget about the Google Maps API, and use OpenLayers instead.

Believe me, I've got hands-on experience with this. I've created countless interactive mapping websites and applications, and I've written code that wrap Google Maps functionality into Delphi components. You can find them on Google code: http://code.google.com/p/delphimaps/

You can also find some example application that I've made with an early version of these components here: Use Googlemap from my Delphi application?

OpenLayers is much more versatile, it's completely open source, and it has a whole community behind it. It can even use Google Maps, but you can easily switch to OpenStreetMaps, Yahoo, Bing, or your own GIS system.

There are many examples online, and you're not tied to stupid rules that are imposed by Google. For example, if you want to use Google Maps via a secure (HTTPS) connection, you have to pay. I never directly use the Google Maps API anymore, and my GIS websites became much better since I started using OpenLayers.

Maybe one day I should wrap OpenLayers into Delphi components, but I now do most stuff in JavaScript instead, and only communicate with my Delphi app when it's really needed, so even with Delphi apps that contain a map, not much GIS stuff is done in Delphi. That turns out to be easier to maintain.

..

Also, OpenLayers doesn't require any internet connection. It can run 100% in your offline browser. Google Maps requires you to have an internet connection, as it downloads parts of its code dynamically, and it always wants to download its maps from Google.

Community
  • 1
  • 1
Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
  • 1
    "I now do most stuff in JavaScript..." - you don't have to any more and you can stay with Pascal. Take a look at Smart Mobile Studio: http://op4js.optimalesystemer.no/about/ – avra Jun 01 '12 at 08:10
  • My bottom line is that I need to capture a route on which a person drives, from start to stop. I need the street name, city, and state/province. Can OpenLayers do this? – rickstep Jun 01 '12 at 14:08
  • I'm not sure what you mean with "capture a route", but if you need to turn coordinates into addresses, you can make use of the Google GeoCoder API. DelphiMaps wraps that for you, and there are two demo's on how to use it. DelphiMaps also wraps Google's routeplanner, and there's a demo for that too. This space is too small to give further explanations on it; ask a new question if you need help with that. – Wouter van Nifterick Jun 02 '12 at 08:46
  • Yes -- turning coordinates into addresses will give me the street name, city, and state/province. The link to the DelphiMaps takes me to a deprecated download. Is there a more recent download somewhere else? – rickstep Jun 11 '12 at 16:45
  • It's best to just use SVN. That way you'll automatically always get the latest version. But I've created a new zipfile with the sourcecode here: http://code.google.com/p/delphimaps/downloads/list – Wouter van Nifterick Jun 11 '12 at 22:31
5

If you are looking for a complete solution to use the Google Maps API with Delphi, I highly recommend the Delphi Framework for Google Maps. It enables to use all API functions without a single line of HTML or JavaScript.

For example:

procedure TForm1.FormShow(Sender: TObject);
begin
  with Script(WebBrowser1) do
    if not APILoaded
      then LoadAPIAsync(InitMap);
end;

procedure TForm1.InitMap(Sender: TObject);
var
  MapOptions: TMapOptions;
begin
  with Sender as TScript do
  begin
    MapOptions:=New(Google.Maps.MapOptions);
    with MapOptions do
    begin
      Zoom:=8;
      Center:=New(Google.Maps.LatLng(-34.397,150.644));
      MapTypeID:=Google.Maps.MapTypeID.Roadmap;
    end;
    New(Google.Maps.Map(MapOptions));
  end;
end;

The route planner is also easily available. There are some demos.

Unfortunately, you must still download it currently from a German forum. A separate website is under construction. If there are problems with the registration or download, I can send an email with the framework.

Regards