目前,我正在做一个像Uber这样的项目。这意味着有两个应用程序:一个用于驱动程序,另一个用于客户。
问题是:司机需要每2秒更新一次他们的位置。客户每2秒拉出最近的所有驱动程序,以实现实时。它会导致数据库查询性能变差。我使用PostgreSQL的立方体和地球距离扩展来计算最近的。
谁能告诉我解决这个问题的最好方法是什么?非常感谢!
发布于 2016-09-22 10:12:41
你可以使用deepstream.io进行实时数据提交,例如从Android
public void onLocationChanged(Location location) {
// get the record
Record record = client.record.getRecord( "driver/14" );
// any kind of data path works
record.set( "position.x", location.getLongitude() );
//as well as any kind of serializable datatype
record.set( "position.y", location.getLatitude() );
}
转到JavaScript
// get the record
var driver = client.record.getRecord( 'driver/14' );
// subscribe to any changes within position
driver.subscribe( 'position', function( position ){
updateMarker( position.x, position.y );
});
例如,与deepstream集成的RethinkDBs geospacial queries相结合,这可能是一个可扩展的解决方案。
Here's an example repo演示了这一点
https://stackoverflow.com/questions/31532962
复制相似问题