Is it possible to know street direction (compass)?
Asked Answered
M

4

5

I'm working on a project where we need to know the direction (compass) of a street. Actually, we only have a GeoPoint (lat;long and heading) we are planning on using reverseGeocoding to tell where is it (which street?); and then we 'd like to know if he's heading in the wrong way.

Google Maps, OSM, Mapquest they all display an arrow over the street which indicates its direction. I guess they draw them dinamically, so they have to know their angle. That's what I'd like to know (if possible)

Thanks in advance!

#

EDIT:

I'm thinking maybe they cut the street into little pieces and then they said "this track of the street goes from (lat1;lng1) to (lat2;lng2)" that would give that track a direction, an so they can draw that arrow. Also not every street is a straight line, so its direction is not only one, it depends on which portion of the street you are in.

Mentor answered 3/3, 2015 at 23:40 Comment(3)
For Google Maps API: there is no indication of a street direction within a reverse geocoding response. IMO, a user driving on a street the wrong way should realize that before your application tells him...Tutuila
Hi! Thanks for your input! The case would be someone making an infraction. Do you know any other way I can figure out the street direction? As said before, if they draw an arrow over the map I'm guessing they have to know the street direction (angle). I don't imaging someone drawing them one by oneMentor
Of course they know it. But you don't have access to every piece of data through documented API methods. I can't think of a way to get that information with the Google Maps API. Maybe with another API. You are right in your edit, streets are not (all) straight.Tutuila
H
6

With OpenStreetMap it is possible to determine whether the street at the current position is a oneway street and whether the user is driving into the wrong direction.

The Overpass API allows to download objects inside a given bounding box (your current location). For downloading streets you have to specify the highway tag, oneway streets are marked by the oneway tag. Ideally you should read a little bit about OSM's basic elements and tags to get an idea about how OSM's internal work. Then start to play around with overpass turbo which is a nice web frontend for Overpass API.

See this example query on overpass turbo:

[out:json][timeout:25];
// gather results
(
  way["highway"](51.04525236350533,13.778518438339233,51.04603818288315,13.779301643371582);
);
// print results
out body;
>;
out skel qt;

It retrieves all ways with a highway tag in the given bounding box.

Note that the result might contain multiple highways if they are contained in the given bounding box, or none of the bounding box is too small.

Heronry answered 4/3, 2015 at 11:58 Comment(0)
S
2

So what you need to know is the street name and when this is a oneway if the driver is going into the right direction (did I correctly understand this?)

To solve this you can use a routing engine like GraphHopper where I am the author of ;) and use the point you have as the starting point.

The end point you can calculate via simple vector mathematics from the starting point and the heading plus e.g. 1 or 2 meter distance.

Then if the beeline distance of those two points is similar to the route distance he is correctly on the track. If the calculated route is more than 2 times the length of the beeline distance then the street is a oneway and he is driving in the wrong direction. See this route (7 meter long) vs. this route (145m). As a nice side effect you also get the street name in the instructions.

BTW: Recorded GPS signal can be erroneous (you should not rely on a single one) and you might have a look into map matching to improve that via many recorded points.

Stretcherbearer answered 4/3, 2015 at 23:29 Comment(0)
L
0

First, you need at least 2 points. Direction is meaningless with just one point.

Once you have your 2 points, use google.maps.geometry.spherical.computeHeading(point1, point2)

There is a nice demo here: https://developers.google.com/maps/documentation/javascript/examples/geometry-headings

Btw, getHeading() is for determining what direction the aircraft was facing when the currently displayed aerial image was taken. AFAIK, any given point that has aerial image mode available usually has 4 views about 90 deg apart from each other, but they don't always line up with the cardinal directions. You change the view by calling setHeading().

Linda answered 4/3, 2015 at 0:13 Comment(3)
Thanks for your answer. If i understood correctly that is not what I'm looking for. getHeading would give my direction and I l'd ike to know the street way of circulation. And knowing that and my own direction I can tell if I'm moving wrong wayMentor
getHeading does not do what you think it does. Check out this example from the documentation: developers.google.com/maps/documentation/javascript/examples/…Linda
I'm sorry for my misunderstanding. I still don't know how to achieve my goal. I'm tracking a car, I know where it is, and where is it going to. I'd like to be able to tell to it "your are driving on xxxxxxxx street, but that street goes from east to west and your driving from west to east. You are in the wrong way". Thank you one more time, thanks for helping meMentor
M
-1

You would want to use getHeading() It returns the compass heading of aerial imagery. The heading value is measured in degrees (clockwise) from cardinal direction North.

Medor answered 3/3, 2015 at 23:57 Comment(2)
Thanks! I think that would give my own heading. And I'd like to know the street direction so I can tell if I'm driving wrong way (intentionally)Mentor
getHeading() of which API? This is not an answer to the original question + it is very low quality.Tutuila

© 2022 - 2024 — McMap. All rights reserved.