How to Draw a Curved Great Circle line in Google Maps

Someone came up to me in a coffee shop yesterday and told me they had a web application in which they wanted to connect two locations on a Google Map with a line. Not a regular straight line, but rather a curved “great circle” line. I mumbled about various possible approaches to this — setting up a custom tile-server and generating lines on the back end, etc. — only to find that this functionality is already build into the Google Maps API:

var polyOptions = {geodesic:true};
var polyline = new GPolyline([
  new GLatLng(61.1699849, -149.944496),
  new GLatLng(46.2361, -63.13)
  ], "#ff0000", 3, 1, polyOptions);
map.addOverlay(polyline);

Add an overlay like this — the key is the geodesic:true — and you go from straight line to curvy one. This is well-documented in the Google Maps API documentation.

Great Circle Line in Google Maps Screen Shot

Comments

oliver's picture
oliver on April 22, 2008 - 17:40

If Google’s so geodesically enlightened, why are they using that archaic projection that portrays Greenland as bigger than Africa?

mark's picture
mark on October 13, 2014 - 20:16

You mean a "Mercator projection". It's not archaic. It's probably the most common type of projection used in cartography today, there are others of course, but anytime you put a 3D map on a 2D screen there must be some distortion somewhere.

sisenca's picture
sisenca on October 18, 2010 - 19:08

oliver because a sphere cannot be shown in 2D map exactly as it is

Add new comment