php 谷歌地图实时追踪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16403475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Real time tracking in google map
提问by user1452485
I already wrote a android apps to upload the lat and long to MySQL database(updated every 2min).
我已经写了一个 android 应用程序将经纬度上传到 MySQL 数据库(每 2 分钟更新一次)。
now, i have no idea how to show the real time location on Google map in the website(php,javascript,html) which means how to dynamic update the Google map markers every 2 min [get the last two minutes records from MySQL database and show the markers(update or disappear)]
现在,我不知道如何在网站(php、javascript、html)中显示谷歌地图上的实时位置,这意味着如何每 2 分钟动态更新谷歌地图标记[从 MySQL 数据库中获取最后两分钟的记录和显示标记(更新或消失)]
and after i click the marker, it should show the info[get from mysql database(not important point because it same with static Google map!?]
在我点击标记后,它应该显示信息[从 mysql 数据库中获取(不重要,因为它与静态谷歌地图相同!?]
just like this: http://traintimes.org.uk/map/tube/
就像这样:http: //traintimes.org.uk/map/tube/
I just know how to do when i just get 1 time (Static Google map!?) with my limited knowledge.
我只知道以我有限的知识获得 1 次(静态 Google 地图!?)时该怎么做。
I have already searched same question in stack overflow and google but i am sorry i still no idea how to do it because of my lack of knowledge.
我已经在堆栈溢出和谷歌中搜索过同样的问题,但很抱歉,由于我缺乏知识,我仍然不知道该怎么做。
anyone could give me some tutorial website or suggestion?
谁能给我一些教程网站或建议?
At last, thank all of you and I still a learner of English,I am sorry about any wrong grammar.
最后,谢谢大家,我还是一个英语学习者,我很抱歉任何错误的语法。
采纳答案by Stephen Blum
Real-time Tracking Geo Latitude/Longitude on a Map
在地图上实时跟踪地理纬度/经度
You are looking to update coordinate entities (lat/lon position) on a map (google maps or otherwise) in real-time as the updates occur. Here is a blog post that may get you started in the right direction: http://blog.pubnub.com/streaming-geo-coordinates-from-mongodb-to-your-iphone-app-with-pubnub-using-websocket-sdk/- this uses MongoDB and Ruby rather than PHP and MySQL. However it will be easy to get things setup in this case with a real-time map in PHP and MySQL on an HTML page with the following details. And there is a video too: https://vimeo.com/60716860
您希望在更新发生时实时更新地图(谷歌地图或其他方式)上的坐标实体(纬度/经度位置)。这是一篇可以让您朝着正确方向开始的博客文章: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
Using MySQL to Trigger Update in Real-time
使用 MySQL 实时触发更新
First you'll want to use either MySQL triggers to push the Lat/Long coords - Invoke pusher when mysql has changed- this uses MySQL Triggers
首先,您需要使用 MySQL 触发器来推送纬度/经度坐标 -当 mysql 更改时调用推送器- 这使用 MySQL 触发器
Or as an alternative you may want to use PHP directly to invoke the push signal using a PHP push SDK as follows: https://github.com/pubnub/php#php-push-api
或者作为替代方案,您可能希望直接使用 PHP 来使用 PHP 推送 SDK 调用推送信号,如下所示:https: //github.com/pubnub/php#php-push-api
$pubnub->publish(array(
'channel' => 'live_map_coords',
'message' => array( 12.3482, 8.3344 )
));
Receiving The Push Message in JavaScript and Showing the Updates on a Map
在 JavaScript 中接收推送消息并在地图上显示更新
<script src=//pubnub.a.ssl.fastly.net/pubnub-3.4.5.min.js></script>
<script>(function(){
PUBNUB.init({
subscribe_key : 'demo'
}).subscribe({
channel : 'live_map_coords',
callback : function(lat_lon) { alert(lat_lon) }
});
})();</script>
Once you have an map.html
page with the above code in it, you can change the alert(lat_log)
message popup with drawing coords on a map. Here is a fully working map drawn example using D3
JavaScript SVG rendering Framework: https://github.com/stephenlb/pubnub-mongo-pipe/blob/master/phone/map.html
一旦您有一个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.
注意:这只是一个起点,并为您提供了入门参考,以使其变得容易和简单,但根据您的应用程序的方向灵活。
Next Steps to Piece Together the Real-time Geo Map
拼凑实时地理地图的后续步骤
You will next want to do the following to complete the process and join together all the separate components listed here.
接下来您需要执行以下操作来完成该过程并将此处列出的所有单独组件连接在一起。
- Modify the
map.html
page for your purposes to display always-visible dots. Note that in the video the dots are temporary beacons that display and vanish rapidly. You'll want to make them persist on the map. This is basically the "Make it look the way you want it"step. - Decide how and when you want to trigger the TCP Socket Push events from PHP or MySQL directly. I'd recommend the PHP approach.
map.html
根据您的目的修改页面以显示始终可见的点。请注意,视频中的点是临时信标,可快速显示和消失。你会想让它们在地图上持久化。这基本上是“让它看起来像你想要的样子”步骤。- 决定如何以及何时直接从 PHP 或 MySQL 触发 TCP 套接字推送事件。 我会推荐 PHP 方法。