How to save marker and polyline in database?How to add polygon in MySQL databaseReference materials for learning Google API V3 with PHP and MySQL (tracking)Drawing polyline that grows as the car moves by taking data from MySql and PHP in Google APIHow to show information window for the marker cluster?Drop Markers and MarkerCluster together from databaseHow to get multiple dynamic custom markers on map using MapBox in MySQL and PHP?Leaflet : How to update polyline ? Live TrackingMapbox personalized icons with cluster and filter checkboxExtracting latitude/longitude from javascript and passing to html formQGIS Start and endpoint marker line and polyline

Extreme, but not acceptable situation and I can't start the work tomorrow morning

Is Social Media Science Fiction?

Is there a familial term for apples and pears?

Email Account under attack (really) - anything I can do?

How can I fix this gap between bookcases I made?

Some basic questions on halt and move in Turing machines

New order #4: World

What is the meaning of "of trouble" in the following sentence?

How can I add custom success page

Could a US political party gain complete control over the government by removing checks & balances?

Does a dangling wire really electrocute me if I'm standing in water?

How many letters suffice to construct words with no repetition?

Patience, young "Padovan"

Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?

Mapping arrows in commutative diagrams

Why was the "bread communication" in the arena of Catching Fire left out in the movie?

Why airport relocation isn't done gradually?

What to wear for invited talk in Canada

Einstein metrics on spheres

Could Giant Ground Sloths have been a Good Pack Animal for the Ancient Mayans

Can a planet have a different gravitational pull depending on its location in orbit around its sun?

Crop image to path created in TikZ?

Is domain driven design an anti-SQL pattern?

extract characters between two commas?



How to save marker and polyline in database?


How to add polygon in MySQL databaseReference materials for learning Google API V3 with PHP and MySQL (tracking)Drawing polyline that grows as the car moves by taking data from MySql and PHP in Google APIHow to show information window for the marker cluster?Drop Markers and MarkerCluster together from databaseHow to get multiple dynamic custom markers on map using MapBox in MySQL and PHP?Leaflet : How to update polyline ? Live TrackingMapbox personalized icons with cluster and filter checkboxExtracting latitude/longitude from javascript and passing to html formQGIS Start and endpoint marker line and polyline






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to store marker and polyline in the database. In this script, I have 3 functions, that is to draw a polyline, marker and the point of destination.



Can anyone fix my script below?



var map;
var __global_node_now = 'null';
var __global_node = false;
var __global_line = false;
var __global_destination = false;
var __global_destination_now = 'null';
var __global_load_json = false;
var __global_arr_node = new Array();
var __global_first_line = 0;

function add_node()
var active_x = document.getElementById('add_nodex');
var active_y = document.getElementById('add_linex');
var active_z = document.getElementById('add_destinationx');
/* disable other tools */
__global_node = true;
__global_line = false;
__global_destination = false;


function add_line()
var active_x = document.getElementById('add_nodex');
var active_y = document.getElementById('add_linex');
var active_z = document.getElementById('add_destinationx');
/* disable other tools */
__global_line = true;
__global_node = false;
__global_destination = false;


function add_destination()
var active_x = document.getElementById('add_nodex');
var active_y = document.getElementById('add_linex');
var active_z = document.getElementById('add_destinationx');
/* disable other tools */
__global_destination = true;
__global_node = false;
__global_line = false;


function edit_destination_name(a, thiis)
var edit_destination = prompt("Edit destination", $(thiis).html());
console.log(window['marker_dest_' + a]);
// id marker_destintation
marker_destination = window['marker_dest_' + a];
// update event popup
if(edit_destination)

// update destination_name by live
$(thiis).html(edit_destination);
// update title marker
marker_destination.setTitle(edit_destination);
console.log(marker_destination.title);
// remove previously event
google.maps.event.clearListeners(marker_destination, 'click');
// popup event
var content = "<span class='destination_name' onclick='edit_destination_name("" + a + "", this)'>" + edit_destination + "</span>";
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker_destination,'click', (function(marker_destination,content,infowindow)
return function()
infowindow.setContent(content);
//console.log(infowindow.getMap());
infowindow.open(map,marker_destination);
;
)(marker_destination,content,infowindow));



var poly;
var map;
var increase = 0;
function initialize()
/* setup map */
var mapOptions =
center: new google.maps.LatLng(-7.977022, 112.634151),
zoom: 15,
zoomControl: true,
streetViewControl: false,
mapTypeControl: false,
gestureHandling: 'greedy'
;
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
/* setup polyline */
var polyOptions =
geodesic: true,
strokeColor: 'rgb(20, 120, 218)',
strokeOpacity: 1.0,
strokeWeight: 2,
editable: true,
;
window['poly' + increase] = new google.maps.Polyline(polyOptions);
window['poly' + increase].setMap(map);

/* create marker and line by click */
google.maps.event.addListener(map, 'click', function(event)

/* if tools 'add destination' is active, create marker */
if( __global_destination == true )
var key_destination = 0;
//__global_destination_now = 'a';
if( __global_destination_now == 'null' )
__global_destination_now = 'a';
key_destination = 0;
else
__global_destination_now = String.fromCharCode( __global_destination_now.charCodeAt(0) + 1 );
key_destination += 1;

console.log(__global_destination_now);
// nama destination
destination_name = "HAE";
window['infowindow'+key_destination] = new google.maps.InfoWindow(
content: '<div>'+ destination_name +'</div>'
);

// add marker destination
icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
var location = event.latLng;
window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
position: location,
map: map,
icon: icons,
draggable: true,
title: '' + __global_destination_now,
);

// id marker_destintation
var marker_destintation = window['marker_dest_' + __global_destination_now];

// popup event
var content = "<span class='destination_name' onclick='edit_destination_name("" + __global_destination_now + "", this)'>" + __global_destination_now + "</span>";
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker_destintation,'click', (function(marker_destintation,content,infowindow)
return function()
infowindow.setContent(content);
infowindow.open(map,marker_destintation);
;
)(marker_destintation,content,infowindow));


/* if tools 'add node' is active, create marker */
if( __global_node == true )
var key_node = 0;
if( __global_node_now == 'null' )
__global_node_now = 'a';
key_node = 0;
else
__global_node_now = String.fromCharCode( __global_node_now.charCodeAt(0) + 1 );
key_destination += 1;


/* draw a new marker */
var location = event.latLng;
var marker = new google.maps.Marker(
position: location,
map: map,
title: '' + __global_node_now,
);

// popup event
var content_marker = "<div>" + __global_node_now + "</div>";
var infowindow_marker = new google.maps.InfoWindow();
google.maps.event.addListener(marker,'click', (function(marker,content_marker,infowindow_marker)
return function()
infowindow_marker.setContent(content_marker);
infowindow_marker.open(map,marker);
;
)(marker,content_marker,infowindow_marker));

/* Add listener to getting latLng marker
* using 'list object event' : this.title, this.position
*/
google.maps.event.addListener(marker, "click", function (evt)

/* if tools 'add line' is active, create first polyline */
if( __global_line == true )

/* first polyline */
var path = window['poly' + increase].getPath();
path.push(event.latLng);

/* temporary for node start - finish for json
* example : 0-1 "coordinates": [[123, 456], [321, 123]]
*/
if( __global_first_line == 0 )
temp_node1 = this.title;


/* jika meng-klik ke marker/node akhir dalam pembuatan polyline */
if( evt.latLng.lat() == event.latLng.lat() && evt.latLng.lng() == event.latLng.lng() && __global_first_line == 1 )
alert('node & line berhasil disambung!');
temp_node2 = this.title;
temp_node_fix = temp_node1 + '-' + temp_node2;
__global_arr_node.push(temp_node_fix);
/* adding id window['poly' + increase] */
increase += 1;
/* reset first polyline */
__global_first_line = 0;

/* reset polyline */
var polyOptions =
geodesic: true,
strokeColor: 'rgb(20, 120, 218)',
strokeOpacity: 1.0,
strokeWeight: 2,
editable: true,
//draggable: true,
;
window['poly' + increase] = new google.maps.Polyline(polyOptions);
window['poly' + increase].setMap(map);
return false; // die()

__global_first_line = 1;

); //end addListener
else if( __global_line == true )
if( __global_first_line == 1 )
var path = window['poly' + increase].getPath();
path.push(event.latLng);
else
alert('klik Node dulu!');


); // end click map


function save_markerlinex()

function load_json()
textarea = document.getElementById('text_json');
val = textarea.value;
if( val.trim() == '' )
return false;

var res = val.split('-------------------------------------');
for( i = 0; i < res.length; i++ )
var res1 = res[i].trim();
var res2 = res1.split('n');
if( res2.length > 1 ) // coordinates is exist
var json = JSON.parse(res2[0]);
var nodes = json.nodes.toString();
var coord = json.coordinates;
for( a = 0; a < coord.length; a++ )
latlngs = coord[a].toString();
splits = latlngs.split(',');
lats = splits[0].trim();
lngs = splits[1].trim();

var pointPoly = new google.maps.LatLng(lats, lngs);
/* first polyline */
var path = window['poly' + increase].getPath();
path.push(pointPoly);
/* draw a new marker */
if( a == 0
increase += 1;
__global_arr_node.push(nodes);

/* reset polyline */
var polyOptions =
geodesic: true,
strokeColor: 'rgb(20, 120, 218)',
strokeOpacity: 1.0,
strokeWeight: 2,
editable: true,
;
console.log( 'ulang' );
window['poly' + increase] = new google.maps.Polyline(polyOptions);
window['poly' + increase].setMap(map);



var res1 = val.split('=====================================');
if( res1.length > 1 )
res_dest = res1[1].trim();
json = JSON.parse(res_dest);
json_root = json.destination;
length_json = json.destination.length;

for( b = 0; b < length_json; b++ )
var chr = String.fromCharCode(97 + b);
__global_destination_now = chr;
latlng1 = json_root[b][chr].toString().split(',');
next_lat1 = latlng1[0].trim();
next_lng2 = latlng1[1].trim();

var pointPath1 = new google.maps.LatLng(next_lat1, next_lng2);
icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
var location = event.latLng;
window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
position: pointPath1,
map: map,
icon: icons,
draggable: true,
title: '' + __global_destination_now,
);



// reset
textarea.value = '';

/* load google maps v3 */
google.maps.event.addDomListener(window, 'load', initialize);

$(document).ready(function()
$('#clear-map').click(clearMap);
);









share|improve this question









New contributor




MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


























    0















    I want to store marker and polyline in the database. In this script, I have 3 functions, that is to draw a polyline, marker and the point of destination.



    Can anyone fix my script below?



    var map;
    var __global_node_now = 'null';
    var __global_node = false;
    var __global_line = false;
    var __global_destination = false;
    var __global_destination_now = 'null';
    var __global_load_json = false;
    var __global_arr_node = new Array();
    var __global_first_line = 0;

    function add_node()
    var active_x = document.getElementById('add_nodex');
    var active_y = document.getElementById('add_linex');
    var active_z = document.getElementById('add_destinationx');
    /* disable other tools */
    __global_node = true;
    __global_line = false;
    __global_destination = false;


    function add_line()
    var active_x = document.getElementById('add_nodex');
    var active_y = document.getElementById('add_linex');
    var active_z = document.getElementById('add_destinationx');
    /* disable other tools */
    __global_line = true;
    __global_node = false;
    __global_destination = false;


    function add_destination()
    var active_x = document.getElementById('add_nodex');
    var active_y = document.getElementById('add_linex');
    var active_z = document.getElementById('add_destinationx');
    /* disable other tools */
    __global_destination = true;
    __global_node = false;
    __global_line = false;


    function edit_destination_name(a, thiis)
    var edit_destination = prompt("Edit destination", $(thiis).html());
    console.log(window['marker_dest_' + a]);
    // id marker_destintation
    marker_destination = window['marker_dest_' + a];
    // update event popup
    if(edit_destination)

    // update destination_name by live
    $(thiis).html(edit_destination);
    // update title marker
    marker_destination.setTitle(edit_destination);
    console.log(marker_destination.title);
    // remove previously event
    google.maps.event.clearListeners(marker_destination, 'click');
    // popup event
    var content = "<span class='destination_name' onclick='edit_destination_name("" + a + "", this)'>" + edit_destination + "</span>";
    var infowindow = new google.maps.InfoWindow();
    google.maps.event.addListener(marker_destination,'click', (function(marker_destination,content,infowindow)
    return function()
    infowindow.setContent(content);
    //console.log(infowindow.getMap());
    infowindow.open(map,marker_destination);
    ;
    )(marker_destination,content,infowindow));



    var poly;
    var map;
    var increase = 0;
    function initialize()
    /* setup map */
    var mapOptions =
    center: new google.maps.LatLng(-7.977022, 112.634151),
    zoom: 15,
    zoomControl: true,
    streetViewControl: false,
    mapTypeControl: false,
    gestureHandling: 'greedy'
    ;
    map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);
    var trafficLayer = new google.maps.TrafficLayer();
    trafficLayer.setMap(map);
    /* setup polyline */
    var polyOptions =
    geodesic: true,
    strokeColor: 'rgb(20, 120, 218)',
    strokeOpacity: 1.0,
    strokeWeight: 2,
    editable: true,
    ;
    window['poly' + increase] = new google.maps.Polyline(polyOptions);
    window['poly' + increase].setMap(map);

    /* create marker and line by click */
    google.maps.event.addListener(map, 'click', function(event)

    /* if tools 'add destination' is active, create marker */
    if( __global_destination == true )
    var key_destination = 0;
    //__global_destination_now = 'a';
    if( __global_destination_now == 'null' )
    __global_destination_now = 'a';
    key_destination = 0;
    else
    __global_destination_now = String.fromCharCode( __global_destination_now.charCodeAt(0) + 1 );
    key_destination += 1;

    console.log(__global_destination_now);
    // nama destination
    destination_name = "HAE";
    window['infowindow'+key_destination] = new google.maps.InfoWindow(
    content: '<div>'+ destination_name +'</div>'
    );

    // add marker destination
    icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
    var location = event.latLng;
    window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
    position: location,
    map: map,
    icon: icons,
    draggable: true,
    title: '' + __global_destination_now,
    );

    // id marker_destintation
    var marker_destintation = window['marker_dest_' + __global_destination_now];

    // popup event
    var content = "<span class='destination_name' onclick='edit_destination_name("" + __global_destination_now + "", this)'>" + __global_destination_now + "</span>";
    var infowindow = new google.maps.InfoWindow();
    google.maps.event.addListener(marker_destintation,'click', (function(marker_destintation,content,infowindow)
    return function()
    infowindow.setContent(content);
    infowindow.open(map,marker_destintation);
    ;
    )(marker_destintation,content,infowindow));


    /* if tools 'add node' is active, create marker */
    if( __global_node == true )
    var key_node = 0;
    if( __global_node_now == 'null' )
    __global_node_now = 'a';
    key_node = 0;
    else
    __global_node_now = String.fromCharCode( __global_node_now.charCodeAt(0) + 1 );
    key_destination += 1;


    /* draw a new marker */
    var location = event.latLng;
    var marker = new google.maps.Marker(
    position: location,
    map: map,
    title: '' + __global_node_now,
    );

    // popup event
    var content_marker = "<div>" + __global_node_now + "</div>";
    var infowindow_marker = new google.maps.InfoWindow();
    google.maps.event.addListener(marker,'click', (function(marker,content_marker,infowindow_marker)
    return function()
    infowindow_marker.setContent(content_marker);
    infowindow_marker.open(map,marker);
    ;
    )(marker,content_marker,infowindow_marker));

    /* Add listener to getting latLng marker
    * using 'list object event' : this.title, this.position
    */
    google.maps.event.addListener(marker, "click", function (evt)

    /* if tools 'add line' is active, create first polyline */
    if( __global_line == true )

    /* first polyline */
    var path = window['poly' + increase].getPath();
    path.push(event.latLng);

    /* temporary for node start - finish for json
    * example : 0-1 "coordinates": [[123, 456], [321, 123]]
    */
    if( __global_first_line == 0 )
    temp_node1 = this.title;


    /* jika meng-klik ke marker/node akhir dalam pembuatan polyline */
    if( evt.latLng.lat() == event.latLng.lat() && evt.latLng.lng() == event.latLng.lng() && __global_first_line == 1 )
    alert('node & line berhasil disambung!');
    temp_node2 = this.title;
    temp_node_fix = temp_node1 + '-' + temp_node2;
    __global_arr_node.push(temp_node_fix);
    /* adding id window['poly' + increase] */
    increase += 1;
    /* reset first polyline */
    __global_first_line = 0;

    /* reset polyline */
    var polyOptions =
    geodesic: true,
    strokeColor: 'rgb(20, 120, 218)',
    strokeOpacity: 1.0,
    strokeWeight: 2,
    editable: true,
    //draggable: true,
    ;
    window['poly' + increase] = new google.maps.Polyline(polyOptions);
    window['poly' + increase].setMap(map);
    return false; // die()

    __global_first_line = 1;

    ); //end addListener
    else if( __global_line == true )
    if( __global_first_line == 1 )
    var path = window['poly' + increase].getPath();
    path.push(event.latLng);
    else
    alert('klik Node dulu!');


    ); // end click map


    function save_markerlinex()

    function load_json()
    textarea = document.getElementById('text_json');
    val = textarea.value;
    if( val.trim() == '' )
    return false;

    var res = val.split('-------------------------------------');
    for( i = 0; i < res.length; i++ )
    var res1 = res[i].trim();
    var res2 = res1.split('n');
    if( res2.length > 1 ) // coordinates is exist
    var json = JSON.parse(res2[0]);
    var nodes = json.nodes.toString();
    var coord = json.coordinates;
    for( a = 0; a < coord.length; a++ )
    latlngs = coord[a].toString();
    splits = latlngs.split(',');
    lats = splits[0].trim();
    lngs = splits[1].trim();

    var pointPoly = new google.maps.LatLng(lats, lngs);
    /* first polyline */
    var path = window['poly' + increase].getPath();
    path.push(pointPoly);
    /* draw a new marker */
    if( a == 0
    increase += 1;
    __global_arr_node.push(nodes);

    /* reset polyline */
    var polyOptions =
    geodesic: true,
    strokeColor: 'rgb(20, 120, 218)',
    strokeOpacity: 1.0,
    strokeWeight: 2,
    editable: true,
    ;
    console.log( 'ulang' );
    window['poly' + increase] = new google.maps.Polyline(polyOptions);
    window['poly' + increase].setMap(map);



    var res1 = val.split('=====================================');
    if( res1.length > 1 )
    res_dest = res1[1].trim();
    json = JSON.parse(res_dest);
    json_root = json.destination;
    length_json = json.destination.length;

    for( b = 0; b < length_json; b++ )
    var chr = String.fromCharCode(97 + b);
    __global_destination_now = chr;
    latlng1 = json_root[b][chr].toString().split(',');
    next_lat1 = latlng1[0].trim();
    next_lng2 = latlng1[1].trim();

    var pointPath1 = new google.maps.LatLng(next_lat1, next_lng2);
    icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
    var location = event.latLng;
    window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
    position: pointPath1,
    map: map,
    icon: icons,
    draggable: true,
    title: '' + __global_destination_now,
    );



    // reset
    textarea.value = '';

    /* load google maps v3 */
    google.maps.event.addDomListener(window, 'load', initialize);

    $(document).ready(function()
    $('#clear-map').click(clearMap);
    );









    share|improve this question









    New contributor




    MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      I want to store marker and polyline in the database. In this script, I have 3 functions, that is to draw a polyline, marker and the point of destination.



      Can anyone fix my script below?



      var map;
      var __global_node_now = 'null';
      var __global_node = false;
      var __global_line = false;
      var __global_destination = false;
      var __global_destination_now = 'null';
      var __global_load_json = false;
      var __global_arr_node = new Array();
      var __global_first_line = 0;

      function add_node()
      var active_x = document.getElementById('add_nodex');
      var active_y = document.getElementById('add_linex');
      var active_z = document.getElementById('add_destinationx');
      /* disable other tools */
      __global_node = true;
      __global_line = false;
      __global_destination = false;


      function add_line()
      var active_x = document.getElementById('add_nodex');
      var active_y = document.getElementById('add_linex');
      var active_z = document.getElementById('add_destinationx');
      /* disable other tools */
      __global_line = true;
      __global_node = false;
      __global_destination = false;


      function add_destination()
      var active_x = document.getElementById('add_nodex');
      var active_y = document.getElementById('add_linex');
      var active_z = document.getElementById('add_destinationx');
      /* disable other tools */
      __global_destination = true;
      __global_node = false;
      __global_line = false;


      function edit_destination_name(a, thiis)
      var edit_destination = prompt("Edit destination", $(thiis).html());
      console.log(window['marker_dest_' + a]);
      // id marker_destintation
      marker_destination = window['marker_dest_' + a];
      // update event popup
      if(edit_destination)

      // update destination_name by live
      $(thiis).html(edit_destination);
      // update title marker
      marker_destination.setTitle(edit_destination);
      console.log(marker_destination.title);
      // remove previously event
      google.maps.event.clearListeners(marker_destination, 'click');
      // popup event
      var content = "<span class='destination_name' onclick='edit_destination_name("" + a + "", this)'>" + edit_destination + "</span>";
      var infowindow = new google.maps.InfoWindow();
      google.maps.event.addListener(marker_destination,'click', (function(marker_destination,content,infowindow)
      return function()
      infowindow.setContent(content);
      //console.log(infowindow.getMap());
      infowindow.open(map,marker_destination);
      ;
      )(marker_destination,content,infowindow));



      var poly;
      var map;
      var increase = 0;
      function initialize()
      /* setup map */
      var mapOptions =
      center: new google.maps.LatLng(-7.977022, 112.634151),
      zoom: 15,
      zoomControl: true,
      streetViewControl: false,
      mapTypeControl: false,
      gestureHandling: 'greedy'
      ;
      map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
      var trafficLayer = new google.maps.TrafficLayer();
      trafficLayer.setMap(map);
      /* setup polyline */
      var polyOptions =
      geodesic: true,
      strokeColor: 'rgb(20, 120, 218)',
      strokeOpacity: 1.0,
      strokeWeight: 2,
      editable: true,
      ;
      window['poly' + increase] = new google.maps.Polyline(polyOptions);
      window['poly' + increase].setMap(map);

      /* create marker and line by click */
      google.maps.event.addListener(map, 'click', function(event)

      /* if tools 'add destination' is active, create marker */
      if( __global_destination == true )
      var key_destination = 0;
      //__global_destination_now = 'a';
      if( __global_destination_now == 'null' )
      __global_destination_now = 'a';
      key_destination = 0;
      else
      __global_destination_now = String.fromCharCode( __global_destination_now.charCodeAt(0) + 1 );
      key_destination += 1;

      console.log(__global_destination_now);
      // nama destination
      destination_name = "HAE";
      window['infowindow'+key_destination] = new google.maps.InfoWindow(
      content: '<div>'+ destination_name +'</div>'
      );

      // add marker destination
      icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
      var location = event.latLng;
      window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
      position: location,
      map: map,
      icon: icons,
      draggable: true,
      title: '' + __global_destination_now,
      );

      // id marker_destintation
      var marker_destintation = window['marker_dest_' + __global_destination_now];

      // popup event
      var content = "<span class='destination_name' onclick='edit_destination_name("" + __global_destination_now + "", this)'>" + __global_destination_now + "</span>";
      var infowindow = new google.maps.InfoWindow();
      google.maps.event.addListener(marker_destintation,'click', (function(marker_destintation,content,infowindow)
      return function()
      infowindow.setContent(content);
      infowindow.open(map,marker_destintation);
      ;
      )(marker_destintation,content,infowindow));


      /* if tools 'add node' is active, create marker */
      if( __global_node == true )
      var key_node = 0;
      if( __global_node_now == 'null' )
      __global_node_now = 'a';
      key_node = 0;
      else
      __global_node_now = String.fromCharCode( __global_node_now.charCodeAt(0) + 1 );
      key_destination += 1;


      /* draw a new marker */
      var location = event.latLng;
      var marker = new google.maps.Marker(
      position: location,
      map: map,
      title: '' + __global_node_now,
      );

      // popup event
      var content_marker = "<div>" + __global_node_now + "</div>";
      var infowindow_marker = new google.maps.InfoWindow();
      google.maps.event.addListener(marker,'click', (function(marker,content_marker,infowindow_marker)
      return function()
      infowindow_marker.setContent(content_marker);
      infowindow_marker.open(map,marker);
      ;
      )(marker,content_marker,infowindow_marker));

      /* Add listener to getting latLng marker
      * using 'list object event' : this.title, this.position
      */
      google.maps.event.addListener(marker, "click", function (evt)

      /* if tools 'add line' is active, create first polyline */
      if( __global_line == true )

      /* first polyline */
      var path = window['poly' + increase].getPath();
      path.push(event.latLng);

      /* temporary for node start - finish for json
      * example : 0-1 "coordinates": [[123, 456], [321, 123]]
      */
      if( __global_first_line == 0 )
      temp_node1 = this.title;


      /* jika meng-klik ke marker/node akhir dalam pembuatan polyline */
      if( evt.latLng.lat() == event.latLng.lat() && evt.latLng.lng() == event.latLng.lng() && __global_first_line == 1 )
      alert('node & line berhasil disambung!');
      temp_node2 = this.title;
      temp_node_fix = temp_node1 + '-' + temp_node2;
      __global_arr_node.push(temp_node_fix);
      /* adding id window['poly' + increase] */
      increase += 1;
      /* reset first polyline */
      __global_first_line = 0;

      /* reset polyline */
      var polyOptions =
      geodesic: true,
      strokeColor: 'rgb(20, 120, 218)',
      strokeOpacity: 1.0,
      strokeWeight: 2,
      editable: true,
      //draggable: true,
      ;
      window['poly' + increase] = new google.maps.Polyline(polyOptions);
      window['poly' + increase].setMap(map);
      return false; // die()

      __global_first_line = 1;

      ); //end addListener
      else if( __global_line == true )
      if( __global_first_line == 1 )
      var path = window['poly' + increase].getPath();
      path.push(event.latLng);
      else
      alert('klik Node dulu!');


      ); // end click map


      function save_markerlinex()

      function load_json()
      textarea = document.getElementById('text_json');
      val = textarea.value;
      if( val.trim() == '' )
      return false;

      var res = val.split('-------------------------------------');
      for( i = 0; i < res.length; i++ )
      var res1 = res[i].trim();
      var res2 = res1.split('n');
      if( res2.length > 1 ) // coordinates is exist
      var json = JSON.parse(res2[0]);
      var nodes = json.nodes.toString();
      var coord = json.coordinates;
      for( a = 0; a < coord.length; a++ )
      latlngs = coord[a].toString();
      splits = latlngs.split(',');
      lats = splits[0].trim();
      lngs = splits[1].trim();

      var pointPoly = new google.maps.LatLng(lats, lngs);
      /* first polyline */
      var path = window['poly' + increase].getPath();
      path.push(pointPoly);
      /* draw a new marker */
      if( a == 0
      increase += 1;
      __global_arr_node.push(nodes);

      /* reset polyline */
      var polyOptions =
      geodesic: true,
      strokeColor: 'rgb(20, 120, 218)',
      strokeOpacity: 1.0,
      strokeWeight: 2,
      editable: true,
      ;
      console.log( 'ulang' );
      window['poly' + increase] = new google.maps.Polyline(polyOptions);
      window['poly' + increase].setMap(map);



      var res1 = val.split('=====================================');
      if( res1.length > 1 )
      res_dest = res1[1].trim();
      json = JSON.parse(res_dest);
      json_root = json.destination;
      length_json = json.destination.length;

      for( b = 0; b < length_json; b++ )
      var chr = String.fromCharCode(97 + b);
      __global_destination_now = chr;
      latlng1 = json_root[b][chr].toString().split(',');
      next_lat1 = latlng1[0].trim();
      next_lng2 = latlng1[1].trim();

      var pointPath1 = new google.maps.LatLng(next_lat1, next_lng2);
      icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
      var location = event.latLng;
      window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
      position: pointPath1,
      map: map,
      icon: icons,
      draggable: true,
      title: '' + __global_destination_now,
      );



      // reset
      textarea.value = '';

      /* load google maps v3 */
      google.maps.event.addDomListener(window, 'load', initialize);

      $(document).ready(function()
      $('#clear-map').click(clearMap);
      );









      share|improve this question









      New contributor




      MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I want to store marker and polyline in the database. In this script, I have 3 functions, that is to draw a polyline, marker and the point of destination.



      Can anyone fix my script below?



      var map;
      var __global_node_now = 'null';
      var __global_node = false;
      var __global_line = false;
      var __global_destination = false;
      var __global_destination_now = 'null';
      var __global_load_json = false;
      var __global_arr_node = new Array();
      var __global_first_line = 0;

      function add_node()
      var active_x = document.getElementById('add_nodex');
      var active_y = document.getElementById('add_linex');
      var active_z = document.getElementById('add_destinationx');
      /* disable other tools */
      __global_node = true;
      __global_line = false;
      __global_destination = false;


      function add_line()
      var active_x = document.getElementById('add_nodex');
      var active_y = document.getElementById('add_linex');
      var active_z = document.getElementById('add_destinationx');
      /* disable other tools */
      __global_line = true;
      __global_node = false;
      __global_destination = false;


      function add_destination()
      var active_x = document.getElementById('add_nodex');
      var active_y = document.getElementById('add_linex');
      var active_z = document.getElementById('add_destinationx');
      /* disable other tools */
      __global_destination = true;
      __global_node = false;
      __global_line = false;


      function edit_destination_name(a, thiis)
      var edit_destination = prompt("Edit destination", $(thiis).html());
      console.log(window['marker_dest_' + a]);
      // id marker_destintation
      marker_destination = window['marker_dest_' + a];
      // update event popup
      if(edit_destination)

      // update destination_name by live
      $(thiis).html(edit_destination);
      // update title marker
      marker_destination.setTitle(edit_destination);
      console.log(marker_destination.title);
      // remove previously event
      google.maps.event.clearListeners(marker_destination, 'click');
      // popup event
      var content = "<span class='destination_name' onclick='edit_destination_name("" + a + "", this)'>" + edit_destination + "</span>";
      var infowindow = new google.maps.InfoWindow();
      google.maps.event.addListener(marker_destination,'click', (function(marker_destination,content,infowindow)
      return function()
      infowindow.setContent(content);
      //console.log(infowindow.getMap());
      infowindow.open(map,marker_destination);
      ;
      )(marker_destination,content,infowindow));



      var poly;
      var map;
      var increase = 0;
      function initialize()
      /* setup map */
      var mapOptions =
      center: new google.maps.LatLng(-7.977022, 112.634151),
      zoom: 15,
      zoomControl: true,
      streetViewControl: false,
      mapTypeControl: false,
      gestureHandling: 'greedy'
      ;
      map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
      var trafficLayer = new google.maps.TrafficLayer();
      trafficLayer.setMap(map);
      /* setup polyline */
      var polyOptions =
      geodesic: true,
      strokeColor: 'rgb(20, 120, 218)',
      strokeOpacity: 1.0,
      strokeWeight: 2,
      editable: true,
      ;
      window['poly' + increase] = new google.maps.Polyline(polyOptions);
      window['poly' + increase].setMap(map);

      /* create marker and line by click */
      google.maps.event.addListener(map, 'click', function(event)

      /* if tools 'add destination' is active, create marker */
      if( __global_destination == true )
      var key_destination = 0;
      //__global_destination_now = 'a';
      if( __global_destination_now == 'null' )
      __global_destination_now = 'a';
      key_destination = 0;
      else
      __global_destination_now = String.fromCharCode( __global_destination_now.charCodeAt(0) + 1 );
      key_destination += 1;

      console.log(__global_destination_now);
      // nama destination
      destination_name = "HAE";
      window['infowindow'+key_destination] = new google.maps.InfoWindow(
      content: '<div>'+ destination_name +'</div>'
      );

      // add marker destination
      icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
      var location = event.latLng;
      window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
      position: location,
      map: map,
      icon: icons,
      draggable: true,
      title: '' + __global_destination_now,
      );

      // id marker_destintation
      var marker_destintation = window['marker_dest_' + __global_destination_now];

      // popup event
      var content = "<span class='destination_name' onclick='edit_destination_name("" + __global_destination_now + "", this)'>" + __global_destination_now + "</span>";
      var infowindow = new google.maps.InfoWindow();
      google.maps.event.addListener(marker_destintation,'click', (function(marker_destintation,content,infowindow)
      return function()
      infowindow.setContent(content);
      infowindow.open(map,marker_destintation);
      ;
      )(marker_destintation,content,infowindow));


      /* if tools 'add node' is active, create marker */
      if( __global_node == true )
      var key_node = 0;
      if( __global_node_now == 'null' )
      __global_node_now = 'a';
      key_node = 0;
      else
      __global_node_now = String.fromCharCode( __global_node_now.charCodeAt(0) + 1 );
      key_destination += 1;


      /* draw a new marker */
      var location = event.latLng;
      var marker = new google.maps.Marker(
      position: location,
      map: map,
      title: '' + __global_node_now,
      );

      // popup event
      var content_marker = "<div>" + __global_node_now + "</div>";
      var infowindow_marker = new google.maps.InfoWindow();
      google.maps.event.addListener(marker,'click', (function(marker,content_marker,infowindow_marker)
      return function()
      infowindow_marker.setContent(content_marker);
      infowindow_marker.open(map,marker);
      ;
      )(marker,content_marker,infowindow_marker));

      /* Add listener to getting latLng marker
      * using 'list object event' : this.title, this.position
      */
      google.maps.event.addListener(marker, "click", function (evt)

      /* if tools 'add line' is active, create first polyline */
      if( __global_line == true )

      /* first polyline */
      var path = window['poly' + increase].getPath();
      path.push(event.latLng);

      /* temporary for node start - finish for json
      * example : 0-1 "coordinates": [[123, 456], [321, 123]]
      */
      if( __global_first_line == 0 )
      temp_node1 = this.title;


      /* jika meng-klik ke marker/node akhir dalam pembuatan polyline */
      if( evt.latLng.lat() == event.latLng.lat() && evt.latLng.lng() == event.latLng.lng() && __global_first_line == 1 )
      alert('node & line berhasil disambung!');
      temp_node2 = this.title;
      temp_node_fix = temp_node1 + '-' + temp_node2;
      __global_arr_node.push(temp_node_fix);
      /* adding id window['poly' + increase] */
      increase += 1;
      /* reset first polyline */
      __global_first_line = 0;

      /* reset polyline */
      var polyOptions =
      geodesic: true,
      strokeColor: 'rgb(20, 120, 218)',
      strokeOpacity: 1.0,
      strokeWeight: 2,
      editable: true,
      //draggable: true,
      ;
      window['poly' + increase] = new google.maps.Polyline(polyOptions);
      window['poly' + increase].setMap(map);
      return false; // die()

      __global_first_line = 1;

      ); //end addListener
      else if( __global_line == true )
      if( __global_first_line == 1 )
      var path = window['poly' + increase].getPath();
      path.push(event.latLng);
      else
      alert('klik Node dulu!');


      ); // end click map


      function save_markerlinex()

      function load_json()
      textarea = document.getElementById('text_json');
      val = textarea.value;
      if( val.trim() == '' )
      return false;

      var res = val.split('-------------------------------------');
      for( i = 0; i < res.length; i++ )
      var res1 = res[i].trim();
      var res2 = res1.split('n');
      if( res2.length > 1 ) // coordinates is exist
      var json = JSON.parse(res2[0]);
      var nodes = json.nodes.toString();
      var coord = json.coordinates;
      for( a = 0; a < coord.length; a++ )
      latlngs = coord[a].toString();
      splits = latlngs.split(',');
      lats = splits[0].trim();
      lngs = splits[1].trim();

      var pointPoly = new google.maps.LatLng(lats, lngs);
      /* first polyline */
      var path = window['poly' + increase].getPath();
      path.push(pointPoly);
      /* draw a new marker */
      if( a == 0
      increase += 1;
      __global_arr_node.push(nodes);

      /* reset polyline */
      var polyOptions =
      geodesic: true,
      strokeColor: 'rgb(20, 120, 218)',
      strokeOpacity: 1.0,
      strokeWeight: 2,
      editable: true,
      ;
      console.log( 'ulang' );
      window['poly' + increase] = new google.maps.Polyline(polyOptions);
      window['poly' + increase].setMap(map);



      var res1 = val.split('=====================================');
      if( res1.length > 1 )
      res_dest = res1[1].trim();
      json = JSON.parse(res_dest);
      json_root = json.destination;
      length_json = json.destination.length;

      for( b = 0; b < length_json; b++ )
      var chr = String.fromCharCode(97 + b);
      __global_destination_now = chr;
      latlng1 = json_root[b][chr].toString().split(',');
      next_lat1 = latlng1[0].trim();
      next_lng2 = latlng1[1].trim();

      var pointPath1 = new google.maps.LatLng(next_lat1, next_lng2);
      icons = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';
      var location = event.latLng;
      window['marker_dest_' + __global_destination_now] = new google.maps.Marker(
      position: pointPath1,
      map: map,
      icon: icons,
      draggable: true,
      title: '' + __global_destination_now,
      );



      // reset
      textarea.value = '';

      /* load google maps v3 */
      google.maps.event.addDomListener(window, 'load', initialize);

      $(document).ready(function()
      $('#clear-map').click(clearMap);
      );






      google-maps-api markers php mysql polyline-creation






      share|improve this question









      New contributor




      MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Apr 4 at 4:41









      Kadir Şahbaz

      4,60221531




      4,60221531






      New contributor




      MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Apr 4 at 4:16









      MALANG aremaMALANG arema

      1




      1




      New contributor




      MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      MALANG arema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "79"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          MALANG arema is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317720%2fhow-to-save-marker-and-polyline-in-database%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          MALANG arema is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          MALANG arema is a new contributor. Be nice, and check out our Code of Conduct.












          MALANG arema is a new contributor. Be nice, and check out our Code of Conduct.











          MALANG arema is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317720%2fhow-to-save-marker-and-polyline-in-database%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

          Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

          Romeo and Juliet ContentsCharactersSynopsisSourcesDate and textThemes and motifsCriticism and interpretationLegacyScene by sceneSee alsoNotes and referencesSourcesExternal linksNavigation menu"Consumer Price Index (estimate) 1800–"10.2307/28710160037-3222287101610.1093/res/II.5.31910.2307/45967845967810.2307/2869925286992510.1525/jams.1982.35.3.03a00050"Dada Masilo: South African dancer who breaks the rules"10.1093/res/os-XV.57.1610.2307/28680942868094"Sweet Sorrow: Mann-Korman's Romeo and Juliet Closes Sept. 5 at MN's Ordway"the original10.2307/45957745957710.1017/CCOL0521570476.009"Ram Leela box office collections hit massive Rs 100 crore, pulverises prediction"Archived"Broadway Revival of Romeo and Juliet, Starring Orlando Bloom and Condola Rashad, Will Close Dec. 8"Archived10.1075/jhp.7.1.04hon"Wherefore art thou, Romeo? To make us laugh at Navy Pier"the original10.1093/gmo/9781561592630.article.O006772"Ram-leela Review Roundup: Critics Hail Film as Best Adaptation of Romeo and Juliet"Archived10.2307/31946310047-77293194631"Romeo and Juliet get Twitter treatment""Juliet's Nurse by Lois Leveen""Romeo and Juliet: Orlando Bloom's Broadway Debut Released in Theaters for Valentine's Day"Archived"Romeo and Juliet Has No Balcony"10.1093/gmo/9781561592630.article.O00778110.2307/2867423286742310.1076/enst.82.2.115.959510.1080/00138380601042675"A plague o' both your houses: error in GCSE exam paper forces apology""Juliet of the Five O'Clock Shadow, and Other Wonders"10.2307/33912430027-4321339124310.2307/28487440038-7134284874410.2307/29123140149-661129123144728341M"Weekender Guide: Shakespeare on The Drive""balcony"UK public library membership"romeo"UK public library membership10.1017/CCOL9780521844291"Post-Zionist Critique on Israel and the Palestinians Part III: Popular Culture"10.2307/25379071533-86140377-919X2537907"Capulets and Montagues: UK exam board admit mixing names up in Romeo and Juliet paper"Istoria Novellamente Ritrovata di Due Nobili Amanti2027/mdp.390150822329610820-750X"GCSE exam error: Board accidentally rewrites Shakespeare"10.2307/29176390149-66112917639"Exam board apologises after error in English GCSE paper which confused characters in Shakespeare's Romeo and Juliet""From Mariotto and Ganozza to Romeo and Guilietta: Metamorphoses of a Renaissance Tale"10.2307/37323537323510.2307/2867455286745510.2307/28678912867891"10 Questions for Taylor Swift"10.2307/28680922868092"Haymarket Theatre""The Zeffirelli Way: Revealing Talk by Florentine Director""Michael Smuin: 1938-2007 / Prolific dance director had showy career"The Life and Art of Edwin BoothRomeo and JulietRomeo and JulietRomeo and JulietRomeo and JulietEasy Read Romeo and JulietRomeo and Julieteeecb12003684p(data)4099369-3n8211610759dbe00d-a9e2-41a3-b2c1-977dd692899302814385X313670221313670221