Use google maps in desktop applications

Google maps is a popular geomap service used by many sites to display maps and locations. The api provides javascript code to integrate itself into any website.

It is now possible to use google maps in desktops applications. Check Terms for more information. For this a browser has to be embedded in the desktop application.

Here is a desktop application made in c++ that uses google maps.

Google map in a desktop application

The application is called Turbotrace and can be downloaded from here.

It uses an embedded browser (IE rendering engine Trident) and loads up html code for showing google maps just like it should be done on a webpage. The only difference is that google will allow to load the map even if the "request" comes from a non-website referer.

The code as usual is simple :


<html>
<body onload="load()" onunload="GUnload()" >
	<div id="map" style="height:100%; width:100%;"></div>
	<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyABvRyN6w066kQnqmhqEy72iYWhTXBudCM&amp;sensor=false"></script>
	<script type="text/javascript">
		//<![CDATA[
		var map = false;
		
		//load google map
		function load() 
		{
			var myOptions = 
			{
				center: new google.maps.LatLng(22, 88),
				zoom: 2,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			
			map = new google.maps.Map( document.getElementById("map") , myOptions);
			document.getElementById("map").google = google;
		}
		//]]>
		</script>
</body>
</html>

You can just put the above code in a html file on your desktop and open it , and it should load the google maps , and you can move around in it.

So all that the desktop application needs to do is to load this html file in an embedded browser. An api key can be generated from the API Console at code.google.com (https://code.google.com/apis/console). You need an api key for Google Maps V3 service. You need to create a "Server Key" without any IP restriction. So this key will allow accessing google maps service from "any ip" machines and desktops are a part of it.







There are different options to integrate a browser in your app depending on the language , api and libraries being used. The above application Turbotrace is build using wxWidgets GUI library and it provides a widget to embed webbrowser. Similar things are available in libraries like MFC , C#.NET , Java etc.
You need to research out the best library for your application and you are done. Most of them should allow executing javascript in the web browser. So you can do things like adding markers etc from within the application.

Last Updated On : 11th March 2012

Subscribe to get updates delivered to your inbox

3 Comments + Add Comment

  • Will the map be loaded if there is no internet connection? If we are using embedded browser component,do we need internet?

  • Hello,
    Thanks, works fine; but how to put a marker ? and is it possible to draw a polygone to define a spécific region ?

    • to put marker or draw lines, run the relevant maps api function through javascript.

Leave a comment