php – Routeboxer服务器端
发布时间:2020-12-13 17:46:23 所属栏目:PHP教程 来源:网络整理
导读:我试图找到一种方法来获取从谷歌的路由器到php的经度和经度界限,然后通过这些限制查询 mysql.然后我将结果输出到json或xml以使用 android maps api v2.我发现这个 http://luktek.com/Blog/2011-02-03-google-maps-routeboxer-in-php,但我认为这只能在地图上
我试图找到一种方法来获取从谷歌的路由器到php的经度和经度界限,然后通过这些限制查询
mysql.然后我将结果输出到json或xml以使用
android maps api v2.我发现这个
http://luktek.com/Blog/2011-02-03-google-maps-routeboxer-in-php,但我认为这只能在地图上的两个点之间进行框,而不是路线本身周围的框,这使得它不够准确.使用javascript不是一个选项,因为我不能将它与google maps api一起使用或从我的数据库中获取结果.有没有办法通过使用一些服务器端代码(最好是PHP,但也可以使用任何其他适用于mysql的语言)来实现这一点,它可以获取边界,查询mysql并将数据输出到json或xml这样它可以被android解析?
解决方法
我终于找到了一个我满意的解决方案.
我不会粘贴每一步,因为它会花费数千行,但简而言之: 1.从Google方向解析此字段api json( https://developers.google.com/maps/documentation/directions/#JSON):“overview_polyline”:{ 2.使用以下方法将折线解码为纬度和经度点: http://unitstep.net/blog/2008/08/02/decoding-google-maps-encoded-polylines-using-php/ 3.下载此 https://github.com/bazo/route-boxer.我将GeoTools php文件中的所有代码堆积到一个文件中,但如果您知道如何使用该文件则不是必需的:) 这是一个使用这些脚本获取这些框的示例: ... $from = "(Startup point for example: "Turku,Finland")"; $to = "(Destination point fro example: "Porvoo,Finland")"; $json_string = file_get_contents("http://maps.googleapis.com/maps/api/directions/json?origin=$from&destination=$to&sensor=false"); $parsed_json = json_decode($json_string,true); $polyline = $parsed_json['routes'][0]['overview_polyline']['points']; $routepoints = decodePolylineToArray($polyline); $collection = new LatLngCollection($routepoints); $boxer = new RouteBoxer(); //calculate boxes with 10km distance from the line between points $boxes = $boxer->box($collection,$distance = 10); foreach($boxes as $row){ $southWestLtd = $row->southWest->latitude; $southWestLng = $row->southWest->longitude; $northEastLtd = $row->northEast->latitude; $northEastLng = $row->northEast->longitude; $query = "SELECT * FROM markers WHERE Latitude > $southWestLtd AND Latitude < $northEastLtd AND Longitude > $southEastLng AND Longitude < $norhtEastLng"; } 运行该查询,它将只为您提供这些框内的标记(或您正在查询的内容).如果您需要更详细的说明,请发表评论.我非常乐意提供帮助,因为我花了很多个夜晚试图找到一个合理的解决方案. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |