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 6092303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:25:36+00:00 2026-05-23T12:25:36+00:00

I created a map which allows users to draw a circle around a point

  • 0

I created a map which allows users to draw a circle around a point with a specified radius. For some reason the circle does not get completely filled in and this is especially noticeable when the map is more zoomed in. Perhaps someone has a solution to fill the circle completely even when viewed at at a higher zoom level

See code below

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
 <style type="text/css">  
    html { height: 100% }   
    body { height: 100%; margin: 0px; padding: 0px }  
    #map_canvas { height: 100% } 
 </style> 
<script type="text/javascript"   
 src="http://maps.google.com/maps/api/js?sensor=false"> 
 </script> 


</script>
<script type= "text/javascript">

   var geocoder;   
    var map;  
    var count=0;
    //Store points in array 
    var points = [];



function initialize() {    
    geocoder = new google.maps.Geocoder();     
    var latlng = new google.maps.LatLng(-34.397, 150.644);    
    var myOptions = {       
    zoom: 3,      
    center: latlng,       
    mapTypeId: google.maps.MapTypeId.ROADMAP    
   }     
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);  
}    
function codeAddress() {    
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {       
    if (status == google.maps.GeocoderStatus.OK) {         
    map.setCenter(results[0].geometry.location);        
    var marker = new google.maps.Marker({          
        map: map,             
        position: results[0].geometry.location
        }); 

    }
     else {        
    alert("Geocode was not successful for the following reason: " + status);       
    }     
    });   
    }
function plusCount(){
if (count==2){
count=0;
}
else{
count=count +1;
}
}   

function drawCircle() {
var address=document.getElementById("address").value;
var radius=document.getElementById("radius").value;
var latitude=40;
var longitude=0;
geocoder.geocode( { 'address': address}, function(results, status){
if (status==google.maps.GeocoderStatus.OK){
latlng=(results[0].geometry.location);
latitude=latlng.lat();
longitude=latlng.lng();
alert(latitude);
alert(longitude);
alert (radius);
}   

else{
    alert("Geocode was not successful for the following reason: " + status);
}
});





//Degrees to radians 
  var d2r = Math.PI / 180;
  alert("calc d2r " + d2r);
 //  Radians to degrees
 var r2d = 180 / Math.PI;
 alert("calc r2d " + r2d);
// Earth radius is 3,963 miles
 var cLat = (radius / 3963) * r2d;
alert("calc cLat " + cLat);
 var cLng = cLat / Math.cos(latitude * d2r);
   alert("calc cLng " + cLng);




  // Calculate the points
  // Work around 360 points on circle
 for (var i=0; i < 360; i++) {

   var theta = Math.PI * (i/16);

   // Calculate next X point 
   circleY = longitude + (cLng * Math.cos(theta));            
    // Calculate next Y point 
   circleX = latitude + (cLat * Math.sin(theta));
    // Add point to array 
    points.push(new google.maps.LatLng(circleX, circleY));


 };


    alert("completed loop");

    var colors=["#CD0000","#2E6444","#003F87" ];

    var Polyline_Path = new google.maps.Polyline({
    path: points,
   strokeColor: colors[count],
    // color of the outline of the polyline
    strokeOpacity: 1,
    // between 0.0 and 1.0
   strokeWeight: 1,
   // The stroke width in pixels
   fillColor: colors[count],
    fillOpacity: .5
   });
    Polyline_Path.setMap(map);


 }

function clearMap(){
if(points){
for( i in points){
points[i].setMap(null);
}
points.length=0;

   }}


</script>
</head>
    <body onload="initialize()"> 
       <div id="map_canvas" style="width:500px; height:460px;
       -moz-outline-radius:20px; -moz-box-sizing:padding-box; -moz-outline-      style:solid ;-moz-outline-color:#9FB6CD; 
    -   moz-outline-width:10px;"></div>  
        <div>     
        Zip Code: <input id="address" type="textbox" value="">    
        Radius:<input id="radius" type="textbox" value="">
        <input type="button" value="Find" onclick="codeAddress() ">   
        <input type="button" value="Draw Radius" onclick= "drawCircle() ; plusCount()">
        <input type="button" value="Reset" onclick= "clearMap()">
    </div> 
</body>
  • 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-05-23T12:25:37+00:00Added an answer on May 23, 2026 at 12:25 pm

    It looks like you are drawing the circle manually, but you could use the
    google.maps.Circle
    which works for me and fills the circle entirely. Here is a snippet I use in my application, which works also in maximum zoom level:

    var circ = new google.maps.Circle({
        'center':lc,
        'clickable':false,
        'fillColor':"#00FFFF",
        'fillOpacity':0.2, 
        'map':currentmap,
        'radius':75, 
        'strokeColor':'#0000A0',
        'strokeOpacity':'0.5'
    });
    

    lc is my center point, currentmap is the map div

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a map which allows the user to plot multiple markers with
I've been working with Google Maps API v3 and created a map which allows
So I created some rspec_scaffold for an Exercise model and added map.resource :exercises to
I have created an application that allows users to capture information for entities based
I'm developing a Facebook app which allow my users to draw their wanted path
I want to create application which would display spatial data on Map. I'm thinking
I am new to iphone development.I have created map applications and displayed the cuurent
I've created a map system for a game that runs on the principle of
I have an ArcGIS map created with Flex. The labels created dynamically are the
I created a map with a few markers and saved it at http://maps.google.com/ .

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.