沿着你的路径寻找特定的城市 [英] Finding particular cities along your Path

查看:83
本文介绍了沿着你的路径寻找特定的城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的建议。我正在创建一个Web应用程序,在那里我需要查找某条特定城市是否沿着我的路线存在。我使用的是谷歌API来获得沿路径的方向,但它不会返回城市之间。



例如,如果我从A - > D旅行,我喜欢知道C→D是否存在沿着我的路径A→D。如果我知道A - > D之间的城市,我可以轻松地做到这一点。但谷歌API并没有透露。有没有人有更好的建议?谢谢 解决方案

城市的名称并不十分准确,您需要城市的LatLng。



基于LatLng,几何库的方法 isLocationOnEdge()允许您确定LatLng(城市)是否存在on(或接近)为路线定义的折线:

  google.maps.geometry.poly 
.isLocationOnEdge (LatLngOfCity,
new google.maps.Polyline({path:google.maps.geometry.encoding.decodePath(response.routes [0] .overview_polyline.points)}),
0000000001));

response 必须是一个directionsResult,最后一个参数是宽容

http:/ /jsfiddle.net/doktormolle/DXCH8/


I need your suggestion. I am creating a web application where I need to find if particular city's exist along my path. I am using google API to get direction along path,but it does not return the cities between.

For Example if I am travelling from A - > D , I like to know whether C ->D exist along my path A - > D . If I know the cities between A -> D , I can easily do that .But google API doesnt reveal that . Does any one have any other better suggestion . Thanks

解决方案

The name of a city isn't very accurate, you'll need a LatLng for the city.

Based on a LatLng the method isLocationOnEdge() of the geometry-library allows you to determine if the LatLng(city) lies on (or is near) the polyline defined for a route:

google.maps.geometry.poly
  .isLocationOnEdge(LatLngOfCity,
                    new google.maps.Polyline({path:google.maps.geometry.encoding.decodePath(response.routes[0].overview_polyline.points)}),
                    0000000001));

response has to be a directionsResult, the last parameter is a tolerance

http://jsfiddle.net/doktormolle/DXCH8/

这篇关于沿着你的路径寻找特定的城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆