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.

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集