Skip to content

Instantly share code, notes, and snippets.

@sjg
Last active December 27, 2015 20:09
Show Gist options
  • Save sjg/7383003 to your computer and use it in GitHub Desktop.
Save sjg/7383003 to your computer and use it in GitHub Desktop.
Get Lat/Lng from Google Earth Web API
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<head>
<title>Google Earth - Get LatLng</title>
<script src="http://www.google.com/jsapi?key=APIKEY"></script>
<script>
google.load("earth", "1");
var ge = null;
function init() {
google.earth.createInstance("map3d", initCallback, failureCallback);
}
function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
google.earth.addEventListener(ge.getView(), 'viewchange', function() {
console.log("N:" + ge.getView().getViewportGlobeBounds().getNorth());
console.log("S:" + ge.getView().getViewportGlobeBounds().getSouth());
console.log("E:" + ge.getView().getViewportGlobeBounds().getEast());
console.log("W:" + ge.getView().getViewportGlobeBounds().getWest());
});
}
function failureCallback(object) {
}
</script>
</head>
<body onload='init()' id='body'>
<center>
<div id='map3d' style='border: 1px solid silver; height: 600px; width: 800px;'></div>
</center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment