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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:19:11+00:00 2026-05-26T02:19:11+00:00

This is my code to draw a polygon on a map… which doesnt work.

  • 0

This is my code to draw a polygon on a map… which doesnt work. Please tell me what I’m doing wrong.

If I add points manually like this:

points.push(new google.maps.LatLng(51.35020072, -2.978521717));
points.push(new google.maps.LatLng(51.35047285, -2.971755353));
points.push(new google.maps.LatLng(51.34943740, -2.969097019));

instead of using the loop it works fine. Any ideas?

    function drawpolygon(areaid) {

    var points = []; 

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "polygons.asmx/GetPolygonsByArea",
        data: '{ id: "' + areaid + '" }',
        dataType: "json",
        success: function (msg) {
            var c = eval(msg.d);
            for (var i in c) {

                var lat = parseFloat(c[i][1]);
                var lng = parseFloat(c[i][2]);

                points.push(new google.maps.LatLng(lat, lng));

            }
        }
    });

    var Area;

    Area = new google.maps.Polygon({
        paths: points,
        strokeColor: "#204F68",
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: "#A1CBE2",
        fillOpacity: 0.35
    });

    Area.setMap(map);

    google.maps.event.addListener(Area, 'click', showArrays);
    infowindow = new google.maps.InfoWindow();
}
  • 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-26T02:19:11+00:00Added an answer on May 26, 2026 at 2:19 am

    I’m not sure what you mean by “adding points manually”, but I think the problem is that the ajax call is asynchronous. So, you’re caling “$.ajax(…)” and then falling right through to the code that creates Area before your points array has anything in it: the asynchronous call to your success function hasn’t happened yet.

    Try rearranging your code so you create Area and do the setMap(map) call in your success function, right after the loop.

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

Sidebar

Related Questions

In this piece of code: ActionController::Routing::Routes.draw do |map| map.resources :line_items map.resources :orders map.resources :products
I have this code in which a user draws some polygon using mouse pointer
I have this code to draw an ellipse in the screen but I don't
I try to draw some lines with different colors. This code tries to draw
Hi I'm using this code below to let a user draw their signature on
For some reason, this code does not actually draw my bitmap file... or show
I've set of n points and I want to draw a n-sided polygon using
I need to draw a Polygon from several points (I have their latitude, longitude).
I am using this code to draw different cubes with different colors using the
my code draw this text upside down. Why? - (void)drawRect:(CGRect)rect { // Drawing code.

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.