Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:18:42+00:00 2026-06-13T18:18:42+00:00

I would like to draw an ellipse on google maps based off four coordinates,

  • 0

I would like to draw an ellipse on google maps based off four coordinates, like the current “rectangle” method available via the API:

var rectangle = new google.maps.Rectangle({
          strokeColor: '#FF0000',
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: '#FF0000',
          fillOpacity: 0.35,
          map: map,
          bounds: new google.maps.LatLngBounds(
            new google.maps.LatLng(33.671068, -116.25128),
            new google.maps.LatLng(33.685282, -116.233942))
        });

(using the bounds paramater).

If that fails, is there an easy way to convert the distance between 2 polygons to a unit of measurement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:18:44+00:00Added an answer on June 13, 2026 at 6:18 pm

    You have to calculate the path yourself. This should help:

    http://mathworld.wolfram.com/Ellipse.html

    Edit: This might be more useful:

    http://www.geocodezip.com/v3_MW_example_eshapes.html

    A v3 port of Mike Williams’ v2 eshapes library, supports ellipse (but not based on the bounds).

    Working example that sizes to the map bounds.

    proof of concept fiddle

    code snippet:

    var map = null;
    
    var myOptions = {
      zoom: 8,
      center: new google.maps.LatLng(43, -79.5),
      mapTypeControl: true,
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      },
      navigationControl: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map"),
      myOptions);
    
    google.maps.event.addListenerOnce(map, "bounds_changed", function() {
      var bounds = map.getBounds();
      var major_axis = google.maps.geometry.spherical.computeDistanceBetween(bounds.getNorthEast(), new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getNorthEast().lng())) / 2;
      var minor_axis = google.maps.geometry.spherical.computeDistanceBetween(
        new google.maps.LatLng(bounds.getCenter().lat(), bounds.getSouthWest().lng()),
        new google.maps.LatLng(bounds.getCenter().lat(), bounds.getNorthEast().lng())) / 2;
    
      // === Ellipse ===
      var point = map.getCenter(); // new google.maps.LatLng(43,-78);
      var ellipse = google.maps.Polygon.Ellipse(point, major_axis, minor_axis, 0, "#000000", 2, 1, "#ffff00", 0.5);
      ellipse.setMap(map);
    });
    
    // This Javascript is based on code provided by the
    // Community Church Javascript Team
    // http://www.bisphamchurch.org.uk/   
    // http://econym.org.uk/gmap/
    
    // EShapes.js
    //
    // Based on an idea, and some lines of code, by "thetoy" 
    //
    //   This Javascript is provided by Mike Williams
    //   Community Church Javascript Team
    //   http://www.bisphamchurch.org.uk/   
    //   http://econym.org.uk/gmap/
    //
    //   This work is licenced under a Creative Commons Licence
    //   http://creativecommons.org/licenses/by/2.0/uk/
    //
    // Version 0.0 04/Apr/2008 Not quite finished yet
    // Version 1.0 10/Apr/2008 Initial release
    // Version 3.0 12/Oct/2011 Ported to v3 by Lawrence Ross
    google.maps.Polygon.Ellipse = function(point, r1, r2, rotation, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts) {
      rotation = rotation || 0;
      return google.maps.Polygon.Shape(point, r1, r2, r1, r2, rotation, 100, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts)
    }
    
    google.maps.Polygon.Shape = function(point, r1, r2, r3, r4, rotation, vertexCount, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts, tilt) {
      var rot = -rotation * Math.PI / 180;
      var points = [];
      var latConv = google.maps.geometry.spherical.computeDistanceBetween(point, new google.maps.LatLng(point.lat() + 0.1, point.lng())) * 10;
      var lngConv = google.maps.geometry.spherical.computeDistanceBetween(point, new google.maps.LatLng(point.lat(), point.lng() + 0.1)) * 10;
      var step = (360 / vertexCount) || 10;
    
      var flop = -1;
      if (tilt) {
        var I1 = 180 / vertexCount;
      } else {
        var I1 = 0;
      }
      for (var i = I1; i <= 360.001 + I1; i += step) {
        var r1a = flop ? r1 : r3;
        var r2a = flop ? r2 : r4;
        flop = -1 - flop;
        var y = r1a * Math.cos(i * Math.PI / 180);
        var x = r2a * Math.sin(i * Math.PI / 180);
        var lng = (x * Math.cos(rot) - y * Math.sin(rot)) / lngConv;
        var lat = (y * Math.cos(rot) + x * Math.sin(rot)) / latConv;
    
        points.push(new google.maps.LatLng(point.lat() + lat, point.lng() + lng));
      }
      return (new google.maps.Polygon({
        paths: points,
        strokeColor: strokeColour,
        strokeWeight: strokeWeight,
        strokeOpacity: Strokepacity,
        fillColor: fillColour,
        fillOpacity: fillOpacity
      }))
    }
    html,
    body,
    #map {
      height: 100%;
      width: 100%;
      margin: 0px;
      padding: 0px
    }
    <script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
    <div id="map"></div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to draw a rectangle (or more) which printed on paper shows
I would like to draw a rectangle around a video playing on my screen.
I would like draw a vector-based graphic within a WPF ListBoxItem. The 2D shapes
I would like to draw a round pie in a rectangle figure. At the
I would like to draw text on a canvas using the Canvas.drawText call for
I would like to draw some shapes on a JPanel by overriding paintComponent .
I would like to draw a chart in OpenGL similar to the donut graph
I would like to draw a line or bar graph using HTML5 canvas. I
I would like to draw a box using SAS/GRAPH with a color gradient (say
in vb.net i would like to draw a regular line on a form. is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.