我必须在40秒后更新我的谷歌地图或申请时间,以便根据我的数据库纬度和经度值更新我的谷歌地图 [英] 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

查看:64
本文介绍了我必须在40秒后更新我的谷歌地图或申请时间,以便根据我的数据库纬度和经度值更新我的谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生/妈妈,

i已经在我的项目上添加谷歌地图,但我必须更新或设置计时器40秒。



i必须在40秒后更新我的谷歌地图或申请时间,以便我的谷歌地图根据我的数据库纬度和经度值更新。我的java脚本鳕鱼是.....







 <   html     xmlns   =  http://www.w3.org/1999/xhtml  >  
< head runat = server >
< title > < < span class =code-leadattribute> / title >
< script type = text / javascript src = http://maps.googleapis.com/maps/api/js?sensor=false >
< / script >
< / head >
< 正文 >

< 表格 id = form1 runat = 服务器 >


< input 类型 = hidden runat = server id = data / >
< input type = hidden runat = 服务器 id = data2 / >
< 输入 type = hidden runat = server id = data3 / >

< asp:UpdatePanel ID = UpdatePanel1 runat = server UpdateMode = 条件 RenderMode = 内联 >
< div id = map style = width:700px;高度:500px > < / div >
< / asp:UpdatePanel >
< script type = text / javascript >

var map ;
函数initialize(x,y){

var latlng = new google.maps.LatLng(x,y);
var myOptions = {
zoom: 8,
中心:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementB yId(map),myOptions);
var marker = new google.maps.Marker

{
position:new google.maps.LatLng(x,y),
map:map,
标题:'点击我'
}
);
var infowindow = new google.maps.InfoWindow({
content:'用户名:< br / > 时间:'+ document.getElementById('data3')。value +' < br / > LatLng:'+ document.getElementById('data') .value +','+ document.getElementById('data2')。value
});
google.maps.event.addListener(marker,'click',function(){
//调用infoWindow的开放方法
infowindow.open(map,marker);
});
}




window.onload = initialize(document.getElementById('data')。value,document.getElementById('data2') 。值);





很快

提前感谢

解决方案

您可以使用 setTimeout javascript函数来实现此功能。

首先制作您的标记对象global(在之外声明它初始化函数。



  var  map; 
var 标记;
var interval = 40 * 1000; // 40秒

< span class =code-keyword> function initialize(x,y){
setTimeout( function (){
updateMarkerPosition (x,y); // 在这里传递新的lat long(位置)。
} ,间隔);

...
}



现在创建一个javascript函数来更新在给定间隔内标记的位置;



  function  updateMarkerPosition(x ,y){
marker.setPosition( new google.maps.LatLng(x,y));

setTimeout( function (){
updateMarkerPosition(x,y); / / 在这里传递新的lat long(位置)。
},interval);
}


dear sir/mam,
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 .....



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
</head>
<body>

    <form id="form1" runat="server">


    <input type="hidden" runat="server" id="data" />
    <input type="hidden" runat="server" id="data2" />
    <input type="hidden" runat="server" id="data3" />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline">
       <div id="map" style="width: 700px; height: 500px"></div>
       </asp:UpdatePanel>
    <script type="text/javascript">

        var map;
        function initialize(x,y) {

            var latlng = new google.maps.LatLng(x,y);
            var myOptions = {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("map"), myOptions);
            var marker = new google.maps.Marker
    (
        {
            position: new google.maps.LatLng(x,y),
            map: map,
            title: 'Click me'
        }
    );
            var infowindow = new google.maps.InfoWindow({
                content: 'User Name:<br/>Time:"'+ document.getElementById('data3').value+'" <br/>LatLng:'+ document.getElementById('data').value +', ' +document.getElementById('data2').value
            });
            google.maps.event.addListener(marker, 'click', function () {
                // Calling the open method of the infoWindow
                infowindow.open(map, marker);
            });
        }


       

        window.onload = initialize(document.getElementById('data').value, document.getElementById('data2').value);



   

  rply soon 

thanks in advance

解决方案

You can use setTimeout javascript function to achieve this functionality.
First of all make your marker object global (declare it outside of initialize function.

var map;
var marker;
var interval=40*1000; //40 seconds

        function initialize(x,y) {
setTimeout(function(){
  updateMarkerPosition(x,y);// pass new lat long(position) here.
},interval);

...
}


now create one javascript function to update position of marker on given interval;

function updateMarkerPosition(x,y){
marker.setPosition(new google.maps.LatLng(x,y));

setTimeout(function(){
updateMarkerPosition(x,y);// pass new lat long(position) here.
},interval);
}


这篇关于我必须在40秒后更新我的谷歌地图或申请时间,以便根据我的数据库纬度和经度值更新我的谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆