在地图上实时跟踪地理纬度/经度
您正在寻找在更新发生时实时更新地图上的坐标实体(纬度/位置)(谷歌地图或其他方式).这是一个博客文章,可能会让您从正确的方向开始:http://blog.pubnub.com/streaming-geo-coordinates-from-mongodb-to-your-iphone-app-with-pubnub-using-websocket-sdk/ – 这使用MongoDB和Ruby而不是PHP和MySQL.然而,在这种情况下,使用PHP和MySQL中的实时地图在HTML页面上进行设置将很容易,具有以下详细信息.还有一个视频:https://vimeo.com/60716860
使用MySQL实时触发更新
首先,您将要使用MySQL触发器来推动Lat / Long协调 – Invoke pusher when mysql has changed – 这使用MySQL触发器
或者作为替代,您可能希望直接使用PHP来使用PHP推送SDK来调用推送信号,如下所示:https://github.com/pubnub/php#php-push-api
$pubnub->publish(array(
'channel' => 'live_map_coords',
'message' => array( 12.3482, 8.3344 )
));
接收JavaScript中的推送消息并在地图上显示更新
PUBNUB.init({
subscribe_key : 'demo'
}).subscribe({
channel : 'live_map_coords',
callback : function(lat_lon) { alert(lat_lon) }
});
})();
一旦你有一个包含上面代码的map.html页面,你可以使用绘图坐标在地图上更改alert(lat_log)消息弹出窗口.这是一个使用D3 JavaScript SVG渲染框架的完全工作的地图绘制示例:https://github.com/stephenlb/pubnub-mongo-pipe/blob/master/phone/map.html
NOTE: This is only a starting point and provides you with references on getting started to make it easy and simple, yet flexible based on the direction you will be taking your app.
实时地理地图的后续步骤
接下来,您将要执行以下操作来完成此过程,并将此处列出的所有单独组件连接在一起.
>修改map.html页面,以显示始终可见的点.请注意,在视频中,这些点是显示并快速消失的临时信标.你会想让他们坚持在地图上.这基本上是“让它看起来像你想要的方式”一步.>决定如何以及何时直接从PHP或MySQL触发TCP Socket Push事件.我建议PHP方法.