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

  • Home
  • SEARCH
  • 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 798905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:02:39+00:00 2026-05-14T23:02:39+00:00

The included JavaScript snippet is supposed to do the following: As the user clicks

  • 0

The included JavaScript snippet is supposed to do the following:

  1. As the user clicks on the map, initialize headMarker and draw a circle (polygon) around it

  2. As the user clicks inside the circle, initialize tailMarker and draw the path between these two markers

1 is happening as expected. But as the user clicks inside the circle, in the function(overlay,point), overlay is non-null while point is null. Because of this, the code fails to initialize tailMarker.

Can someone tell me a way out.

GEvent.addListener(map, "click", function(overlay,point) {
    if (isCreateHeadPoint) {
        // add the head marker
        headMarker = new GMarker(point,{icon:redIcon,title:'0'});
        map.addOverlay(headMarker);
        isCreateHeadPoint = false;
        // draw the circle
        drawMapCircle(point.lat(),point.lng(),1,'#cc0000',2,0.8,'#0',0.1);
    } else {
        // add the tail marker
        tailMarker = new GMarker(point,{icon:greenIcon,title:''});
        map.addOverlay(tailMarker);
        isCreateHeadPoint = true;
        // load thes path from head to tail
        direction.load("from:" + headMarker.getPoint().lat()+ ", " + 
                        headMarker.getPoint().lng()+ " " +
                       "to:" + tailMarker.getPoint().lat() + "," +
                        tailMarker.getPoint().lng(), 
                       {getPolyline:true}); 
    }
});
  • 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-14T23:02:39+00:00Added an answer on May 14, 2026 at 11:02 pm

    All you need to do is to set the clickable: false option in the GPolygon constructor of your circle. The following is an example that I used to answer another similar question on Stack Overflow:

    <!DOCTYPE html>
    <html> 
    <head> 
       <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
       <title>Google Maps Clicking Inside a Polygon</title> 
       <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false" 
                  type="text/javascript"></script>
    </head> 
    <body onunload="GUnload()">
       <div id="map" style="width: 450px; height: 300px"></div> 
    
       <script type="text/javascript"> 
          var map = new GMap2(document.getElementById("map"));
          map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    
          GEvent.addListener(map, "click", function(overlay, latlng) {
             var lat = latlng.lat();
             var lon = latlng.lng();
             var latOffset = 0.01;
             var lonOffset = 0.01;
             var polygon = new GPolygon([
                new GLatLng(lat, lon - lonOffset),
                new GLatLng(lat + latOffset, lon),
                new GLatLng(lat, lon + lonOffset),
                new GLatLng(lat - latOffset, lon),
                new GLatLng(lat, lon - lonOffset)
             ], "#f33f00", 5, 1, "#ff0000", 0.2, { clickable: false });
    
             map.addOverlay(polygon);
          });
       </script> 
    </body> 
    </html>
    

    Screenshot of the above example:

    Google Maps Clicking Inside a Polygon

    I used diamonds instead of circles, because they are easier to draw in the v2 API. Note that the latlng parameter of the click listener would have been null if the polygons were not created with the clickable: false option.

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

Sidebar

Related Questions

I have included Javascript with <%= javascript_include_tag application %> in my Rails 3.2 application.
Is there a way to have Expression Language (EL) expressions included JavaScript files be
Let's say I do this: $(#content).load(...); Within what I'm loading some javascript is included:
So I only want this JavaScript to be included in the response to the
I have a NetBeans javascript project with several included paths for plugins. I do
I'm having trouble trying to use a function in a javascript file I've included
I am trying to setup ext javascript grid within zend framework mvc. I included
Stuck with a jquery ajax form submission! Here's the code snippet: Javascript/ HTML Code:
I'm new to jQuery and JavaScript I have managed to get a small snippet
Where can I find documentation on running JavaScript code inside a PDF? I've never

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.