So you have geographic coordinates for the city limits? If so, then you would test for intersections against the polygon that is the city limits, and the line segments that are the route, which is a different problem than you outlines before. For that, you would want look for algorithms concerning testing for intersections of lines and polygons, of course, rather than calculating distance of a point from a line segment...if you're not clear as to why, consider a square with opposite corners at, say, (0, 0) and (10, 10), with a line from (-100, 5) to (100, 5). Clearly, none of the points of the line are anywhere near the coordinates of the square, but the line (in this case, your route) definitely intersects the polygon.
-G On Jul 30, 2009, at 1:50 PM, Belthasar wrote: > > Thanks for your help. I'll try that. > > I'm trying to see if I route passes through a city's limits. I already > have all the data, I just needed to know how to compare. > > Thanks! > > On Jul 30, 1:19 pm, Gregory Short <[email protected]> wrote: >> I don't think that functionality is built into the API (almost >> certain >> it's not) but one solution would be to take each segment of a route >> (necessarily a line-segment), and check if the lat/lon is on that >> segment. Of course, it'd probably never be *exactly* on the segment, >> but you could do an approximate comparison, i.e. at your current lat, >> find the lon of the line segment at the same lat, and see how close >> the two lon's are. Better yet would be to find the distance from you >> current point to the line along the direction that is perpendicular >> to >> the line. Do a search for "calculate distance from point to line" and >> you should find some resources on that. Then you can just specify a >> threshold radius and calculate your true/false from that. >> >> This could get expensive for long/detailed routes, of course, so >> you'd >> need to do some optimization via clipping...an option here would be >> to >> use the start/end points of each line segment as coordinates for a >> bounding box, and do some clipping against those before doing the >> actual comparison. >> >> All in all, I don't imagine it would be a terribly difficult thing to >> do. That being the case, though, maybe someone else has done it. Have >> you looked around for third-party/independent solutions? >> >> -G >> >> On Jul 30, 2009, at 12:49 PM, Belthasar wrote: >> >> >> >> >> >>> I was wondering if there was a function that took a set of longitude >>> and latitude parameters and told if they were in the current trip? >> >>> Thanks for your help.- Hide quoted text - >> >> - Show quoted text - > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---
