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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:49:06+00:00 2026-06-09T23:49:06+00:00

Base on this http://jsfiddle.net/kaiser/wzcst/light/ example, but the marker in circle is not accurate, when

  • 0

Base on this http://jsfiddle.net/kaiser/wzcst/light/ example, but the marker in circle is not accurate, when the marker is outside circle and near to circle it is consider inside the circle which is not wanted.

Is there any other idea?

code snippet (from linked fiddle):

window.onload = function init() {
  var
    contentCenter = '<span class="infowin">Center Marker (draggable)</span>',
    contentA = '<span class="infowin">Marker A (draggable)</span>',
    contentB = '<span class="infowin">Marker B (draggable)</span>';
  var
    latLngCenter = new google.maps.LatLng(37.081476, -94.510574),
    latLngCMarker = new google.maps.LatLng(37.0814, -94.5105),
    latLngA = new google.maps.LatLng(37.2, -94.1),
    latLngB = new google.maps.LatLng(38, -93),
    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 7,
      center: latLngCenter,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: false
    }),
    markerCenter = new google.maps.Marker({
      position: latLngCMarker,
      title: 'Location',
      map: map,
      draggable: true
    }),
    infoCenter = new google.maps.InfoWindow({
      content: contentCenter
    }),
    markerA = new google.maps.Marker({
      position: latLngA,
      title: 'Location',
      map: map,
      draggable: true
    }),
    infoA = new google.maps.InfoWindow({
      content: contentA
    }),
    markerB = new google.maps.Marker({
      position: latLngB,
      title: 'Location',
      map: map,
      draggable: true
    }),
    infoB = new google.maps.InfoWindow({
      content: contentB
    })
    // exemplary setup: 
    // Assumes that your map is signed to the var "map"
    // Also assumes that your marker is named "marker"
    ,
    circle = new google.maps.Circle({
      map: map,
      clickable: false,
      // metres
      radius: 100000,
      fillColor: '#fff',
      fillOpacity: .6,
      strokeColor: '#313131',
      strokeOpacity: .4,
      strokeWeight: .8
    });
  // attach circle to marker
  circle.bindTo('center', markerCenter, 'position');

  var
  // get the Bounds of the circle
    bounds = circle.getBounds()
    // Note spans
    ,
    noteA = jQuery('.bool#a'),
    noteB = jQuery('.bool#b');

  noteA.text(bounds.contains(latLngA));
  noteB.text(bounds.contains(latLngB));

  // get some latLng object and Question if it's contained in the circle:
  google.maps.event.addListener(markerCenter, 'dragend', function() {
    latLngCenter = new google.maps.LatLng(markerCenter.position.lat(), markerCenter.position.lng());
    bounds = circle.getBounds();
    noteA.text(bounds.contains(latLngA));
    noteB.text(bounds.contains(latLngB));
  });

  google.maps.event.addListener(markerA, 'dragend', function() {
    latLngA = new google.maps.LatLng(markerA.position.lat(), markerA.position.lng());
    noteA.text(bounds.contains(latLngA));
  });

  google.maps.event.addListener(markerB, 'dragend', function() {
    latLngB = new google.maps.LatLng(markerB.position.lat(), markerB.position.lng());
    noteB.text(bounds.contains(latLngB));
  });

  google.maps.event.addListener(markerCenter, 'click', function() {
    infoCenter.open(map, markerCenter);
  });

  google.maps.event.addListener(markerA, 'click', function() {
    infoA.open(map, markerA);
  });

  google.maps.event.addListener(markerB, 'click', function() {
    infoB.open(map, markerB);
  });

  google.maps.event.addListener(markerCenter, 'drag', function() {
    infoCenter.close();
    noteA.html("draggin&hellip;");
    noteB.html("draggin&hellip;");
  });

  google.maps.event.addListener(markerA, 'drag', function() {
    infoA.close();
    noteA.html("draggin&hellip;");
  });

  google.maps.event.addListener(markerB, 'drag', function() {
    infoB.close();
    noteB.html("draggin&hellip;");
  });
};
body {
  margin: 0;
  padding: 0
}
html,
body,
#map {
  height: 100%;
  font-family: Arial, sans-serif;
  font-size: .9em;
  color: #fff;
}
#note {
  text-align: center;
  padding: .3em;
  10px;
  background: #009ee0;
}
.bool {
  font-style: italic;
  color: #313131;
}
.info {
  display: inline-block;
  width: 40%;
  text-align: center;
}
.infowin {
  color: #313131;
}
#title,
.bool {
  font-weight: bold;
}
<script src="http://maps.googleapis.com/maps/api/js"></script>
<div id="note"><span id="title">&raquo;Inside the circle?&laquo;</span>
  <hr /><span class="info">Marker <strong>A</strong>: <span id="a" class="bool"></span></span>&larr;&diams;&rarr; <span class="info">Marker <strong>B</strong>: <span id="b" class="bool"></span></span>
</div>
<div id="map">test</div>
  • 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-09T23:49:07+00:00Added an answer on June 9, 2026 at 11:49 pm

    A google.maps.LatLngBounds is a rectangle. You need a polygon "contains" function. For a circle this can be reduced to testing whether the point is less than the radius away from the center.

    Example

    code snippet:

    window.onload = function init() {
      var
        contentCenter = '<span class="infowin">Center Marker (draggable)</span>',
        contentA = '<span class="infowin">Marker A (draggable)</span>',
        contentB = '<span class="infowin">Marker B (draggable)</span>';
      var
        latLngCenter = new google.maps.LatLng(37.081476, -94.510574),
        latLngCMarker = new google.maps.LatLng(37.0814, -94.5105),
        latLngA = new google.maps.LatLng(37.2, -94.1),
        latLngB = new google.maps.LatLng(38, -93),
        map = new google.maps.Map(document.getElementById('map'), {
          zoom: 7,
          center: latLngCenter,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          mapTypeControl: false
        }),
        markerCenter = new google.maps.Marker({
          position: latLngCMarker,
          title: 'Center of Circle',
          map: map,
          draggable: true
        }),
        infoCenter = new google.maps.InfoWindow({
          content: contentCenter
        }),
        markerA = new google.maps.Marker({
          position: latLngA,
          title: 'A',
          map: map,
          label: "A",
          draggable: true
        }),
        infoA = new google.maps.InfoWindow({
          content: contentA
        }),
        markerB = new google.maps.Marker({
          position: latLngB,
          title: 'B',
          map: map,
          label: "B",
          draggable: true
        }),
        infoB = new google.maps.InfoWindow({
          content: contentB
        })
        // exemplary setup: 
        // Assumes that your map is signed to the var "map"
        // Also assumes that your marker is named "marker"
        ,
        circle = new google.maps.Circle({
          map: map,
          clickable: false,
          // metres
          radius: 100000,
          fillColor: '#fff',
          fillOpacity: .6,
          strokeColor: '#313131',
          strokeOpacity: .4,
          strokeWeight: .8
        });
      // attach circle to marker
      circle.bindTo('center', markerCenter, 'position');
    
      var
      // get the Bounds of the circle
        bounds = circle.getBounds()
        // Note spans
        ,
        noteA = jQuery('.bool#a'),
        noteB = jQuery('.bool#b');
    
      noteA.text((100000 > google.maps.geometry.spherical.computeDistanceBetween(markerA.getPosition(), markerCenter.getPosition())));
      noteB.text((100000 > google.maps.geometry.spherical.computeDistanceBetween(markerB.getPosition(), markerCenter.getPosition())));
    
      // get some latLng object and Question if it's contained in the circle:
      google.maps.event.addListener(markerCenter, 'dragend', function() {
        latLngCenter = markerCenter.position;
        noteA.text((100000 > google.maps.geometry.spherical.computeDistanceBetween(markerA.getPosition(), markerCenter.getPosition())));
        noteB.text((100000 > google.maps.geometry.spherical.computeDistanceBetween(markerB.getPosition(), markerCenter.getPosition())));
      });
    
      google.maps.event.addListener(markerA, 'dragend', function() {
        latLngA = markerA.position;
        noteA.text((100000 > google.maps.geometry.spherical.computeDistanceBetween(markerA.getPosition(), markerCenter.getPosition())));
      });
    
      google.maps.event.addListener(markerB, 'dragend', function() {
        latLngB = markerB.position;
        noteB.text((100000 > google.maps.geometry.spherical.computeDistanceBetween(markerB.getPosition(), markerCenter.getPosition())));
      });
    
      google.maps.event.addListener(markerCenter, 'click', function() {
        infoCenter.open(map, markerCenter);
      });
    
      google.maps.event.addListener(markerA, 'click', function() {
        infoA.open(map, markerA);
      });
    
      google.maps.event.addListener(markerB, 'click', function() {
        infoB.open(map, markerB);
      });
    
      google.maps.event.addListener(markerCenter, 'drag', function() {
        infoCenter.close();
        noteA.html("draggin&hellip;");
        noteB.html("draggin&hellip;");
      });
    
      google.maps.event.addListener(markerA, 'drag', function() {
        infoA.close();
        noteA.html("draggin&hellip;");
      });
    
      google.maps.event.addListener(markerB, 'drag', function() {
        infoB.close();
        noteB.html("draggin&hellip;");
      });
    };
    body {
      margin: 0;
      padding: 0
    }
    html,
    body,
    #map {
      height: 100%;
      font-family: Arial, sans-serif;
      font-size: .9em;
      color: #fff;
    }
    #note {
      text-align: center;
      padding: .3em;
      10px;
      background: #009ee0;
    }
    .bool {
      font-style: italic;
      color: #313131;
    }
    .info {
      display: inline-block;
      width: 40%;
      text-align: center;
    }
    .infowin {
      color: #313131;
    }
    #title,
    .bool {
      font-weight: bold;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
    <div id="note"><span id="title">&raquo;Inside the circle?&laquo;</span>
      <hr /><span class="info">Marker <strong>A</strong>: <span id="a" class="bool"></span></span>&larr;&diams;&rarr; <span class="info">Marker <strong>B</strong>: <span id="b" class="bool"></span></span>
    </div>
    <div id="map">test</div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a look at this JSFiddle: http://jsfiddle.net/kZ3Af/25/ I have the base navigation pinned down
I am developing a web app base on this guide: http://www.asp.net/data-access/tutorials/declarative-parameters-cs I am able
I have picked up this code(DragandDrop.jsp) from this page :: http://jsfiddle.net/petersendidit/S4QgX/ I am getting
i have this jsfiddle http://jsfiddle.net/danieltulp/gz5gN/ what i want to do is fiter a unordered
For this fiddle http://jsfiddle.net/hNx6E/13/ What I believe is going on is different browsers have
Been trying to see how flexible this is. http://jsfiddle.net/PJSha/4/ i have changed the get
As in http://nant.sourceforge.net/release/latest/help/functions/nant.get-base-directory.html , they explaint the meaning of this function is: The base
So I found this: http://tiles.apache.org/framework/tutorial/advanced/nesting-extending.html Here is the example: <definition name=myapp.homepage template=/layouts/classic.jsp> <put-attribute name=title
I got a problem with the div. It must look like this: http://cl.ly/2r0S043m301p410T2e3z but
I'd like to base this question on the basis of the response posted by

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.