Javascript 谷歌地图v3同步和更新标记
我花了一上午的时间搜索一些简单但同时又灵活的东西,用于快递,比如小公司或小团体/在地图上组织他们自己和订单/目的地。而我在几个小时后就放弃了搜索,浏览了数以万亿计的帖子:并浏览了许多商业软件。我花了最后一个小时制作了我自己的,并得到了我自己的应用程序,但我的脑海中提出了很多问题,所以我想开始它的开源项目,通过这个简短的介绍和下面的代码与大家分享,希望我能找到一些好的答案或好的想法。如何在任何浏览器、任何设备(包括移动互联网)上高效使用。 我一直在寻找正确的方法,使地图基本上实时更新。 设定间隔!?无论如何,我所有的浏览器都会在一段时间后冻结并停止更新,而我希望它能在需要时24/7/365运行。我真的很感激如果有人能引导我至少正确的方向,使这同步更稳定。 提前谢谢 克罗巴尔贡菲格酒店 应用程序Javascript 谷歌地图v3同步和更新标记,javascript,jquery,google-maps,jquery-mobile,google-maps-api-3,Javascript,Jquery,Google Maps,Jquery Mobile,Google Maps Api 3,我花了一上午的时间搜索一些简单但同时又灵活的东西,用于快递,比如小公司或小团体/在地图上组织他们自己和订单/目的地。而我在几个小时后就放弃了搜索,浏览了数以万亿计的帖子:并浏览了许多商业软件。我花了最后一个小时制作了我自己的,并得到了我自己的应用程序,但我的脑海中提出了很多问题,所以我想开始它的开源项目,通过这个简短的介绍和下面的代码与大家分享,希望我能找到一些好的答案或好的想法。如何在任何浏览器、任何设备(包括移动互联网)上高效使用。 我一直在寻找正确的方法,使地图基本上实时更新。 设定间隔!
首先要做的是更改setInterval'syncData',10000;对于SetTimeOutsyncData10000;。使用setInterval,它崩溃可能并不奇怪。setTimeout应该给它一个战斗的机会。我不知道我是怎么错过的:谢谢你指出这一点。我更喜欢后端开发人员,所以这种事情偶尔会发生一次,你可能会嘲笑我的服务器端代码!是否更改$.postmaster\u server.url+sync\u controller+sync\u action.updateLatLng,{latlng:lat+@+lng},functiondata,服务器1\u状态{…};到$.postmaster\u server.url+sync\u controller+sync\u action.updateLatLng,{latlng:lat+@+lng}.donefunctiondata,服务器1\u状态{…};有什么帮助吗?也许你应该看看WebSocket和
/***********************************
* Config
************************************/
/* Master Server */ var master_server = {
url : 'https://0.0.0.0/',
status : false,
connectionFail : "Connection to Master Server Failed"
}
/* Slave Server */ var slave_server = {
url : 'https://0.0.0.0/',
status : false,
connectionFail : "Connection to Slave Server Failed"
}
/* Sync controller */ var sync_controller = '/datasync/';
/* Sync actions */
var sync_action = {
updateLatLng : 'updatewithgeo/'
}
/***********************************/
var car = false;
var order = false;
var order_icon = "static_icon.png";
var customMsg = {
PositionFail : "Because Default lat lng and getCurrentPosition are not set app will not try to sync! It will try again shotwhile"
}
// Can define default lat lng
var lat = false;
var lng = false;
/***********************************/
function syncData()
{
//Temporarly clearing markers to avoid marker[$i] to be duplicated if position is changed
if(markers){$('#map_canvas').gmap('clear', 'markers');}
// Exhange data with server
$('#map_canvas').gmap('getCurrentPosition', function(position, status) {
if ( status === 'OK' ) {
lat = position.coords.latitude;
lng = position.coords.longitude;
}
if (!lat){
console.log(customMsg.PositionFail);
setTimeout('syncData()', 10000);
throw new Error(customMsg.PositionFail);
return;
}
$.post(master_server.url+sync_controller+sync_action.updateLatLng, {latlng : lat+"@"+lng}, function(data, Server_1_Status) {
if(Server_1_Status != 'OK')
{
// If request to master server then here would be place to connect to slave server(s)
console.log(master_server.connectionFail);
setTimeout('syncData()', 10000);
throw new Error(master_server.connectionFail);
return;
}
// If there is no errors
$.each( data.couriers, function(i, courier) {
// If markers are identified correctly when they are returned from server
// then addMarker should only add new markers and
// existing markers shuld be updated (setPosition)
$('#map_canvas').gmap('addMarker', {
'position': new google.maps.LatLng(courier.latitude, courier.longitude),
'bounds': true,
'icon' : courier.icon,
'title' : courier.name
}).click(function() {
$('#map_canvas').gmap('openInfoWindow', { 'content': courier.content }, this);
});
});
$.each( data.orders, function(i, order) {
$('#map_canvas').gmap('addMarker', {
'position': new google.maps.LatLng(order.latitude, order.longitude),
'bounds': true,
'title' : order.address,
'icon' : ""
}).click(function() {
// Populating order view and forms to take / confirm delivery and send digital signature
$('#OrderViewTitle').html('<h1>'+order.orderID+order.address+'</h1>');
$('#OrderData').html('<p><b>'+order.customerID+'</b><br><b>Order:</b>'+order.salesorder+'</p>');
document.getElementById('TakeDelivery').value = order.orderID;
document.getElementById('DeliveryComplete').value = order.orderID;
$('#OrderView').popup("open");
});
});
}, "json");
$('#map_canvas').gmap('refresh');
setTimeout('syncData()', 10000);
});
}
$(document).ready(function() {
courierApp.add(function() {
$('#map_canvas').gmap().bind('init', function() {
syncData();
});
}).load();
});