0
votes

i need help with google map

I wanna without refresh map change marker

i get data from mysql and create marker

my file:

function initialize(){

var latlng = new google.maps.LatLng(55.472627, 23.15918);

var geocoder; var map; var markersArray = []; var infos = [];

var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP };

var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

var encodedString; var stringArray = [];

encodedString = document.getElementById("encodedString").value; stringArray = encodedString.split("**");

var x; for (x = 0; x < stringArray.length; x = x + 1){

var addressDetails = [];

addressDetails = stringArray[x].split(",");

var lat = new google.maps.LatLng(addressDetails[0], addressDetails[1]); console.log(lat);
console.log(addressDetails[0], addressDetails[1]);

var marker = new google.maps.Marker({
map: map,
position: lat,
icon: addressDetails[2],
title: "Atnaujinta: "+addressDetails[3]+""

            });
      }
    }setInterval('updateMap()', 10000);
        </script>

    </head>
    <?php 
    //get data form mysql
    mysql_connect('localhost', 'adena_root', 'gintariukas1');
    mysql_select_db('adena_nav');

    $encodedString = "";
    $x = 0;

    $mysql = mysql_query("SELECT X,Y,marker,data FROM nav");

    while ($row = mysql_fetch_array($mysql, MYSQL_NUM)){
        if ( $x == 0 ){
             $separator = "";
        }else{
          $separator = "****";
        }

      $encodedString = $encodedString.$separator.
        "".$row[0].
        ",".$row[1].
        ",".$row[2].
      ",".$row[3];
        $x = $x + 1;


    }
    ?>
    <body onload="initialize()">
    <input type="hidden" id="encodedString" name="encodedString" value="<?php echo $encodedString; ?>" />

    <div id="map_canvas"></div>
    </body>
    </html>

maybe someone knows?:)

1

1 Answers

0
votes

You can do this by using AJAX. First create a separate page that will display your map data in JSON format then fetch them in JavaScript to display them to the map. Here's a nice tutorial although it uses Google Maps v2, you can simple just change them to v3 code.

AJAX Storing and Retrieving Points – Tutorial