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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:56:22+00:00 2026-06-15T14:56:22+00:00

I have what I believe to be very simple code. I draw a polygon,

  • 0

I have what I believe to be very simple code. I draw a polygon, a marker and then throw an alert if the point I have hard-coded is within the polygon. Yet when I run this I get an ‘Uncaught TypeError: Cannot call method 'lng' of undefined‘ error in the console.

My code is as follows:

   function initialize() {


        var mapOptions = {
          center: new google.maps.LatLng(38.990842,-76.93625),
          zoom: 17,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);

      var box = [new google.maps.LatLng(38.9913160,-76.937079),
      new google.maps.LatLng(38.991333,-76.936119),
      new google.maps.LatLng(38.990287, -76.936108),
      new google.maps.LatLng(38.990278,-76.937057),
      new google.maps.LatLng(38.990495,-76.937052),
      new google.maps.LatLng(38.990499,-76.936424),
      new google.maps.LatLng(38.991091,-76.93643),
      new google.maps.LatLng(38.991104,-76.937079)
      ];

        var mPoint = [new google.maps.LatLng(38.991300,-76.936165)];
  var marker = new google.maps.Marker({
    map: map, 
    position: new google.maps.LatLng(38.991300,-76.936165),
    //position: new google.maps.LatLng(mPoint),
    draggable: true
  });

        var AVpoly = new google.maps.Polygon({path:box,
  strokeColor:"#0000FF",
  strokeOpacity:0.8,
  strokeWeight:2,
  fillColor:"#0000FF",
  fillOpacity:0.4});

      AVpoly.setMap(map);
marker.setMap(map);
if(google.maps.geometry.poly.containsLocation(google.maps.LatLng(38.990842,-76.93625), box) == true) {
 alert("yes");
}

      }

I cannot see anything wrong with this nor do I see why the alert if not firing. I did even change it to false in the off-chance my geometry was wrong….

  • 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-15T14:56:23+00:00Added an answer on June 15, 2026 at 2:56 pm

    Box is not a google.maps.Polygon; it is an array of google.maps.LatLng objects. Use AVpoly instead (the documentation specifies the second argument is a Polygon).

    That doesn’t work, you are also missing the “new” for the google.maps.LatLng constructor. This does work (using the marker.getPosition method which returns a google.maps.LatLng):

    var marker = new google.maps.Marker({
        map: map, 
        position: new google.maps.LatLng(38.991300,-76.936165),
        draggable: true
      });
    
    var AVpoly = new google.maps.Polygon({path:box,
        map: map, 
      strokeColor:"#0000FF",
      strokeOpacity:0.8,
      strokeWeight:2,
      fillColor:"#0000FF",
      fillOpacity:0.4});
    
      if(google.maps.geometry.poly.containsLocation(marker.getPosition(), AVpoly) == true) {
        alert("yes");
     }
    

    Working (if annoying) example

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

Sidebar

Related Questions

I have a very strange bug, which I believe is caused by some code
I have a simple question regarding code blocks within statements, and variables. My script
I have some very simple code which works perfect for what look I'm trying
This is a very simple task in every language I have ever used, but
I have a very simple compound dataset, about 1 million rows of a compound
I have the following very simple and (abridged) classes: // IEntry interface public interface
I have copied a very simple JQuery delayed overlay popup into Wordpress, yet it's
I was writing a very simple piece of code given in the cuda by
I have a very simple project that involves drawing a shape with drawRect, but
I have been asked to write a (very) simple program for a set of

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.