dou4064 2013-01-15 15:43 采纳率: 100%
浏览 98

Jquery DataTables可排序距离列

SO I have jQuery DataTables setup and running fine. My eventual goal, is to allow the user to use google places autocomplete, to update their location, and then to have a 'sortable' distance column added to my DataTables table, upon refresh.

The plan is is to have a button next to the text input of google autocomplete, that says use this address, once user searches for and finds an address using autocomplete, and then pushes the button , I want to (probably)send them to a loading page for a few seconds whilst we

1)read the text string, format it for use with google geo coding api, aka

"Cranbourne, Victoria, Australia" ----> "Cranbourne+Victoria+Australia"

2)insert it in a geocode request

3)extract the lat and lon values from the resulting json, and assign them to vars

Now comes the hard part, I was thinking using some php, to calculate the distance between the users(lat,long), and every entry that was in the DataTable table, which was was populated with sql data using a foreign key (all sql rows have lat lon data)

Then I was thinking of sending said entries to an xml, only this time every entry will have an extra value "DISTANCE".

Of coarse with some clever code this whole thing wont take a second, the new DataTable table is then populated with the xml, only this time it contains a distance column with distance values for every row, which of coarse will be sortable, without any DataTables hacks what so ever.

So am I stupid, or is this somewhat of a good idea, is there an easier way?

I would really like some answers to this thank you.

  • 写回答

2条回答 默认 最新

  • doubinduo3364 2013-01-15 15:49
    关注

    That actually could be difficult (depending on your math expertise), because of the fact that it requires using spherical geometry. You might consider using an API:

    https://developers.google.com/maps/documentation/distancematrix/

    If you want to try doing it yourself, you might want to use a class written for that, such as:

    http://www.phpclasses.org/browse/file/36294.html

    The second option is probably better, because Google has limits on its API. Once you have a way of calculating distance, it's a simple matter to query the database and create the XML. I don't know why you want to use XML instead of json, but the PHP function json_encode() might make it simpler, and it's supported by DataTables.

    评论

报告相同问题?

悬赏问题

  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取