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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:34:17+00:00 2026-06-17T02:34:17+00:00

I have this code here that is attempting to work out if a point

  • 0

I have this code here that is attempting to work out if a point latLng passes through a polygon Maps.area.

Maps.ui.contains = function(latLng){
    //poly.getBounds gets the 'box' around the polygon
    if(!Maps.ui.getBounds().contains(latLng))
        return false;
    //So we dont need to check t/f, we either set it or we dont
    var inPolygon = false;
    var count = 0;

    Maps.area.getPaths().forEach(function(el0, index0){
        var last = el0.getLength() - 1;
        el0.forEach(function(el1, index1){
            count += Maps.ui.ray_intersect_segment(latLng, el1, el0.getAt(last));
            last = index1; 
        });
    });

    if(Maps.area.getPaths().getLength()%2 == 0)
        return count%2==0;
    else
        return count%2!=0;


}

var eps = 0.0001;
var inf = 1e600;
Maps.ui.ray_intersect_segment = function(point, i1, i2){
    var p = point;
    var segment = (i1.lng() > i2.lng())?[i2, i1]:[i1, i2];

    p = (p.lng() == segment[0].lng() || p.lng() == segment[1].lng())?new google.maps.LatLng(p.lng() + eps):p;

    if(p.lng() < segment[0].lng() || p.lng() > segment[1].lng() || p.lat() > [segment[0].lat(), segment[1].lng()].max())
        return 0;
    if(p.lat() < [segment[0].lat(), segment[1].lat()].min())
        return 1;

    var a = (segment[0].lat() != segment[1].lat())?(segment[1].lng() - segment[0].lng())/(segment[1].lat() - segment[0].lat()):inf;
    var b = (segment[0].lat() != p.lat()) ? (p.lng() - segment[0].lng())/(p.lat() - segment[0].lat()):inf;

    return (b > a)?1:0;
}

Maps.ui.getBounds = function() {
    //Lets make a box
    var bounds = new google.maps.LatLngBounds();
    //Get all the points lines of the polly
    var paths = Maps.area.getPaths();
    for (var p = 0; p < paths.getLength(); p++)
        //To store each path
        var path = paths.getAt(p);
        //Now lets expand the box
        for (var i = 0; i < path.getLength(); i++)
            //Add each point of the line to the 'box' making it bigger each time
            bounds.extend(path.getAt(i));
    //Reaturn the bounds, this has a contains method so we can check if the latLng is in it. 
    return bounds;
}

Array.prototype.max = function() {
  return Math.max.apply(null, this)
}

Array.prototype.min = function() {
  return Math.min.apply(null, this)
}

But I can’t seem to work it out. For a simple triangle or square it works perfectly, but when we get to something like this it doesn’t work because we can’t figure out whether count should be even or odd

enter image description here

  • 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-17T02:34:18+00:00Added an answer on June 17, 2026 at 2:34 am

    The Google Maps API v3 spherical geometry library has the poly.contains. Takes a LatLng and a Polygon and tells you if the point is in the polygon.

    containsLocation(point:LatLng, polygon:Polygon)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html code that i want to edit with jQuery. Here is
I have no idea what this means. But here is the code that it
I have this code here printf '$request1 = select * from whatever where this
I have this code here, which is intended to allow any type of arguments:
I have this code here, {foreach from=$cart.cartItems item=item name=cart} <div id=cart2Produkt> <p>{if $item.Product.ID} <a
I have this code here: var Person = (function() { var name; var PersonConstructor
So I have this code here: <table> <tr> <td width=200px valign=top> <div class=left_menu> <div
i have this quick issue please. I have this code here which permits me
I have this code down here. When format.js fires I want to serve to
I have this code right here, where the $friends variable is an array with

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.