Update google map after 40 seconds so that my google map updated in ASP.Net

Last Reply one year ago By Shashikant

Posted one year ago

dear sir
i have add google map on my project but i have to do it update or set timer for 40 seconds.

i have to update my google map after 40 seconds or apply time so that my google map updated according to my database latitude and longtitude values. my java script cod is .....

Posted one year ago

Please refer below code.I have set refresh of google map every 10 seconds,you can set it to 45 secons(45000 ms).

HTML

<div>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
        window.onload = function () {
            LoadGoogleMap();
            setInterval(function () {
                LoadGoogleMap();
            }, 10000);
        }
        function LoadGoogleMap() {
            var markers = GetMapData();
            var mapOptions = {
                center: new google.maps.LatLng(markers[0].Latitude, markers[0].Longitude),
                zoom: 8,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var infoWindow = new google.maps.InfoWindow();
            var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
            for (i = 0; i < markers.length; i++) {
                var data = markers[i]
                var myLatlng = new google.maps.LatLng(data.Latitude, data.Longitude);
                var marker = new google.maps.Marker({
                    position: myLatlng,
                    map: map,
                    title: data.Name
                });
                (function (marker, data) {
                    google.maps.event.addListener(marker, "click", function (e) {
                        infoWindow.setContent(data.Description);
                        infoWindow.open(map, marker);
                    });
                })(marker, data);
            }
        }

        function GetMapData() {
            var json = '';
            $.ajax({
                type: "POST",
                url: "CS.aspx/GetData",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (resp) {
                    json = resp.d;
                },
                error: function () { debugger; }
            });
            return json;
        }
    </script>
    <div id="dvMap" style="width: 500px; height: 500px">
    </div>
</div>

C#

[WebMethod]
public static List<object> GetData()
{
    List<object> lists = new List<object>();
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand("select * from Locations");
    using (SqlConnection con = new SqlConnection(conString))
    {
        cmd.Connection = con;
        cmd.Connection.Open();
        using (SqlDataReader sdr = cmd.ExecuteReader())
        {
            while (sdr.Read())
            {
                lists.Add(new
                {
                    Name = sdr["Name"],
                    Latitude = sdr["Latitude"],
                    Longitude = sdr["Longitude"]
                    Description = sdr["Description"]
                });
            }
        }
        cmd.Connection.Close();
    }
    return lists;
}

Screenshot

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html