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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:43:27+00:00 2026-05-31T15:43:27+00:00

I don’t have too much experience with JavaScript and Google Maps Api. What I

  • 0

I don’t have too much experience with JavaScript and Google Maps Api.
What I want to achieve:
I have a map, where user can either put marker or draw polygon. I’m using gmap3 plugin and I’ve managed to do everything I wanted with markers (like adding, editing, dragging, removing etc), but I have problem with polygons.
Here’s the basic code:

    $('#map-mappoints').gmap3(
    {
        action:'init',
        options:{
            zoom: 7
        }
        ,
        events: {
            click: function(event, data) {
                if($(".map #poly").hasClass('active')){
                    placePoly(data.latLng);
                } else {
                    placeMarker(data.latLng);
                }
            }
        }
    },
    {
        action:"autofit"
    }
    );


    function placePoly(location) {
        $('#map-mappoints').gmap3({ 
            action: 'addPolygon',
            options:{
                strokeColor: "#FF0000",
                strokeOpacity: 0.8,
                strokeWeight: 2,
                fillColor: "#FF0000",
                fillOpacity: 0.35
            },
            callback: function(polygon){
                var path = polygon.getPath();
                path.push(location);
                console.log(path);
            }
        }
        )
    } 

I can see in console that it creates poly, but it adds only one path element, which is logic as it’s triggered after each click on map, but I have no idea how I should make it to continue adding new elements to polygon, and then let user stop (probably by some button in toolbar), and create new after clicking “new poly”.

Thank you for any hints.

ps.
English is not my native language, so I’m sorry for any mistakes, I’ve tried to avoid them 😉

  • 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-31T15:43:28+00:00Added an answer on May 31, 2026 at 3:43 pm

    Read below the title Parameters of gmap3

    http://gmap3.net/documentation.html

    For it main use, gmap3 takes objects as parameters. Each object is an
    action to execute. The actions are executed in their order in the
    parameters list, and each time, once the previous is finished. This
    example first initialise the google map, and then add two markers

    path

    The ordered sequence of coordinates that designates a closed loop. Unlike polylines, a polygon may consist of one or more paths. As a result, the paths property may specify one or more arrays of LatLng coordinates. Simple polygons may be defined using a single array of LatLngs. More complex polygons may specify an array of arrays. Any simple arrays are convered into MVCArrays. Inserting or removing LatLngs from the MVCArray will automatically update the polygon on the map.

    The MVCArray is a mutable array, so you can add more lat,long coordinates to the array and the polygons will automatically be updated.

    Hope this helps you out!

    greetz

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

Sidebar

Related Questions

I don't have much PHP experience and I want to know how to best
Don't have much to say, just can get into the event handler. XAML: <Grid>
I don't have any experience in updating a Rails app and when I google
I don't like Jackson. I want to use ajax but with Google Gson. So
Don't know why but I can't find a solution to this. I have 3
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
Don't know how to google for such, but is there a way to query
I don't want PHP errors to display /html, but I want them to display
Don't know if I worded the question right, but basically what I want to
Don't know if anyone can help me with this or if it's even possible.

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.