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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:59:35+00:00 2026-06-12T00:59:35+00:00

I have a google map where the user can create a polyline. I have

  • 0

I have a google map where the user can create a polyline. I have stored the polyline (lat,lng)coordinates into an array. Now i want to use php or javascript to transfer these coordinates to a mysql database or is there other better options? How should i proceed?

Here is my code:

(function() {
    window.onload = function() {

    var path;
    var marker;
    var infowindow;
    var places = [];

    //create reference to div tag in HTML file
    var mapDiv = document.getElementById('map');

    // option properties of map
    var options = { 
            center: new google.maps.LatLng(-20.2796, 57.5074),
            zoom : 16,
            mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    // create map object
    var map = new google.maps.Map(mapDiv, options);

    // create MVC array to populate on click event
    var route = new google.maps.MVCArray();

    var polyline = new google.maps.Polyline({
        path: route,
        strokeColor: '#ff0000',
        strokeOpacity: 0.6,
        strokeWeight: 5
    });

    polyline.setMap(map);

    // create click event,attach to map and populate route array

    google.maps.event.addListener(map,'click', function(e) {

        // create reference to polyline object
         path = polyline.getPath();

         // add the position clicked on map to MVC array
        path.push(e.latLng);

    });

    // display coordinates
    document.getElementById('coords').onclick = function() {

        for(var i = 0; i < path.getLength(); i++) {

            alert('coords: ' + path.getAt(i).toUrlValue(2) +'\n');
        }


    }

    // create marker on right click
        google.maps.event.addListener(map,'rightclick', function(e) {

                marker = new google.maps.Marker({
                position: e.latLng,
                map: map
            });
                places.push(e.latLng);

                // get coordinates in infowindow on click

                google.maps.event.addListener(marker,'click', function(event){

                    if(!infowindow) {

                        infowindow = new google.maps.InfoWindow();

                    }
                    infowindow.setContent('coords: ' + marker.getPosition().toUrlValue(3));
                    infowindow.open(map,marker);
                });

            });

    };

})();
  • 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-12T00:59:37+00:00Added an answer on June 12, 2026 at 12:59 am

    All right now, here is the database solution for you:

    Table paths will store the paths you have, from your array.

    CREATE TABLE `gmap`.`paths` (
      `pID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
      `pName` VARCHAR(75) NOT NULL,
      `pStartLat` VARCHAR(25) NOT NULL,
      `pStartLng` VARCHAR(25) NOT NULL,
      `pAverageSpeed` FLOAT NOT NULL,
      PRIMARY KEY (`pID`)
    )
    ENGINE = MyISAM;
    

    Table paths will store your user/path name (whatever you want) in pName field, starting point in pStartLat/pStartLng fields, pAverageSpeed is of course average speed (don’t know if you want it, just in case) and pID is identifier which you will use with another table:

    CREATE TABLE `gmap`.`coords` (
      `cID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
      `cLat` VARCHAR(25) NOT NULL,
      `cLng` VARCHAR(25) NOT NULL,
      `cSpeed` FLOAT NOT NULL,
      `cPath` INTEGER UNSIGNED NOT NULL,
      PRIMARY KEY (`cID`)
    )
    ENGINE = MyISAM;
    

    This table will let you store coordinates – with speed to each one.

    Now, let’s say you want to show path called ‘TestOne’.

    // Connect to the database - I assume you can do that
    // and retrieve data
    
    SELECT * FROM paths WHERE pName = "TestOne"
    

    Now you got ID, name, starting point coordinates and average speed in table (mysql_fetch_assoc would be great for that).

    Then, using the ID you can retrieve the rest of the coordinates:

    SELECT * FROM coords WHERE cPath = ID
    

    And now, using e. g. while loop, you can retrieve all coordinates into an array.

    Of course first you have to store that data using INSERT INTO construction or similar 🙂

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

Sidebar

Related Questions

I'm using Google Maps to make a map that can load markers with lat/lng
i have google Maps and when the user touch any point in the map
I have a google map that takes and put coordinates from input fields .
I have embedded a Google Map in my website. I want to change its
i have a multiple marker Google map, it works fine but i want set
On GAE, a non-gmail user can create a Google Account using their non-gmail email
I want to create a GAS standalone web app that will have a google
Background / Concept: I want to create an application that can help user searching
Hi everyone! Im working on a google map project where the user can type
I want to create a store locator with Google Maps. I have a database

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.