Does Here map iOS sdk provides Highway direction?
Example: While driving on US Highways/Interstate, Here map is providing information like I-5 or WA-14.
Can we get which highway/interstate direction we are heading into. Like I-5 N or WA-14 S.
You can allways use course infromation taken from currentPosition(NMAGeoPositon object) of the NMAPositionManager.
Swift
NMAPositionManager.sharedInstance().currentPosition?.course
or Objective-C
[NMAPositionManager sharedPositioningManager].currentPosition.course
Valid course values are in the range [0, 360), with 0 degrees representing north and values increasing clockwise. Thus, east is 90 degrees, south is 180 degrees, and so on. Will be NMAGeoPositionUnknownValue if unknown.
Also it can be obtained from waypoint course.
calculatedRoute.waypoints[idx].course;
or aliases 'start', 'destination' can be used
calculatedRoute.start.course;
calculatedRoute.destination.course;
Another one is to use mapOrientation of maneuver
calculatedRoute.maneuvers[idx].mapOrientation
The angle (from north) at the start of the maneuver, in degrees. Zero represents true-north, with increasing values representing a clockwise progression of map orientation.
Related
The iPhone gyroscope receives rotation data relative to some reference attitude and it doesn't change (unless multiplied.) Lets say I face the wall using my iPhone camera, and rotate 45 degrees left (roll += PI/4.)
Now, if I lift the phone towards the ceiling, both yaw and pitch change since the coordinate space is fixed (world coordinate space, doesn't move or rotate with the phone.) Is there a way to determine this angle (the one between the floor plane and the camera direction vector), roll, yaw and pitch given?
Edit: Instead of opening another question I'll try here. Luc's solution works. But how to get the other two angles of rotation? I've read the info on the posted link but it's been years since I studied linear algebra. This might be more math than a programming question, actually.
I don't really code for iPhone so I'll trust you on the "real world coordinates" frame.
In that case, you want the dot product between both z-axis' vectors. That'll give you the cosine of the angle you're looking for, pretty close thus. Since an angle between planes only really makes sense as a value between 0° and 90°, you actually have all the information you need in that cosine.
And there is no latex formatting here, otherwise I'd go into a bit more of detail, but read this page if you're interested, I'll just include the final result here, the rotation matrix for your three rotations :
Now the z-axis' vector of the horizontal plan is (0,0,1) (read this as a vertical vector though) and rotated with this matrix, you simply get its third column.
So we want to have the dot product between that third column and our (0,0,1) vector, so you get cos(β)cos(γ) which is cos(pitch)*cos(roll)
In conclusion, the angle between your plans is arccos(cos(pitch)*cos(roll)). This value will tell you how much your iPhone is inclined, not in which direction of course. But you can work that out from the values of the vector (rightmost column of the matrix) we spoke of.
I'm trying to iteratively traverse the United States in 1 mile increments using latitude and longitude coordinates. Essentially, once I start (lets say in Portland, OR), I want to move south in one mile increments until I reach the southernmost boundary of the United States that is of the same latitude as Portland, OR. At this point, I want to start back at the northernmost part and move one mile east, repeating the entire process until I get to the east coast. I need to aggrigate these longitude/latitude points in a database.
My question is: Is it accurate to step through latitude and longitude by calculating the next lat/long pair using a delta of 1 mile each time, or are there simpler and more elegant methods to achieve my end goal?
I suppose you could start with the lat/lon of Portland, OR and the lat/lon of the bottom boundary. Compute the distance using Haversine found here: http://www.movable-type.co.uk/scripts/latlong.html
Using the distance above, loop through each mile using a the section Destination point given distance and bearing from start point from the website above. For moving south, your bearing will 180 deg (use π in the formula as they expect radians). For moving east, your bearing will be 90 deg (π/2).
In my project my users can choose to be put in a random position inside a given, circular area.
I have the latitude and longitude of the center and the radius: how can I calculate the latitude and longitude of a random point inside the given area?
(I use PHP but examples in any language will fit anyway)
You need two randomly generated numbers.
Thinking about this using rectangular (Cartesian) (x,y) coordinates is somewhat unnatural for the problem space. Given a radius, it's somewhat difficult to think about how to directly compute an (Δx,Δy) delta that falls within the circle defined by the center and radius.
Better to use polar coordinates to analyze the problem - in which the dimensions are (r1, Θ). Compute one random distance, bounded by the radius. Compute a random angle, from 0 to 360 degrees. Then convert the (r,Θ) to Cartesian (Δx,Δy), where the Cartesian quantities are simply offsets from your circle center, using the simple trigonometry relations.
Δx = r * cos(Θ)
Δy = r * sin(Θ)
Then your new point is simply
xnew = x + Δx
ynew = y + Δy
This works for small r, in which case the geometry of the earth can be approximated by Euclidean (flat plane) geometry.
As r becomes larger, the curvature of the earth means that the Euclidean approximation does not match the reality of the situation. In that case you will need to use the formulas for geodesic distance, which take into account the 3d curvature of the earth. This begins to make sense, let's say, above distances of 100 km. Of course it depends on the degree of accuracy you need, but I'm assuming you have quite a bit of wiggle room.
In 3d-geometry, you once again need to compute 2 quantities - the angle and the distance. The distance is again bound by your r radius, except in this case the distance is measured on the surface of the earth, and is known as a "great circle distance". Randomly generate a number less than or equal to your r, for the first quantity.
The great-circle geometry relation
d = R Δσ
...states that d, a great-circle distance, is proportional to the radius of the sphere and the central angle subtended by two points on the surface of the sphere. "central angle" refers to an angle described by three points, with the center of the sphere at the vertex, and the other two points on the surface of the sphere.
In your problem, this d must be a random quantity bound by your original 'r'. Calculating a d then gives you the central angle, in other words Δσ , since the R for the earth is known (about 6371.01 km).
That gives you the absolute (random) distance along the great circle, away from your original lat/long. Now you need the direction, quantified by an angle, describing the N/S/E/W direction of travel from your original point. Again, use a 0-360 degree random number, where zero represents due east, if you like.
The change in latitude can be calculated by d sin(Θ) , the change in longitude by d cos(Θ). That gives the great-circle distance in the same dimensions as r (presumably km), but you want lat/long degrees, so you'll need to convert. To get from latitudinal distance to degrees is easy: it's about 111.32 km per degree regardless of latitude. The conversion from longitudinal distance to longitudinal degrees is more complicated, because the longitudinal lines are closer to each other nearer the poles. So you need to use some more complex formulae to compute the change in longitude corresponding to the selected d (great distance) and angle. Remember you may need to hop over the +/- 180° barrier. (The designers of the F22 Raptor warplane forgot this, and their airplanes nearly crashed when attempting to cross the 180th meridian.)
Because of the error that may accumulate in successive approximations, you will want to check that the new point fits your constraints. Use the formula
Δσ = arccos( cos(Δlat) - cos(lat1)*cos(lat2)*(1 - cos(Δlong) ) .
where Δlat is the change in latitude, etc.
This gives you Δσ , the central angle between the new and old lat/long points. Verify that the central angle you've calcuated here is the same as the central angle you randomly selected previously. In other words verify that the computed d (great-circle-distance) between the calculated points is the same as the great circle distance you randomly selected. If the computed d varies from your selected d, you can use numerical approximation to improve the accuracy, altering the latitude or longitude slightly until it meets your criterion.
This can simply be done by calculating a random bearing (between 0 and 2*pi) and a random distance between 0 and your desired maximum radius. Then compute the new (random) lat/lon using the random bearing/range from your given lat/lon center point. See the section 'Destination point given distance and bearing from start point' at this web site: http://www.movable-type.co.uk/scripts/latlong.html
Note: the formula given expects all angles as radians (including lat/lon). The resulting lat/lon with be in radians also so you will need to convert to degrees.
I am working on a Blackberry application in which I need to retrieve the Angle difference when the device moves. It means the difference of angle between when the movement starts and ends. It must be 25 degrees to call some function.
In simple words, call a function when the device moves by 25 degrees.
Please read AccelerometerSensor docs, it is available in API 4.7.0 and higher. All data that you can retrieve is described in class AccelerometerData, it is orientation and acceleration (gravity data).
It is described more in details how to get angle from gravity sensor data in JavaME docs, "Mobile Sensor API" section:
If the phone was placed flat, the accelerometer would tell us that the acceleration along the z-axis (up and down) is about 1000 (this value represents 1G). The accelerations along the X and Y axises (sideways) would be about 0 since the phone is sitting still and gravity only works downwards. Flipping the phone over with the screen facing down, the accelerometer would give us the value of -1000 on the Z-axis. Standing on its side, would give us a value of 1000 or -1000 along either the X- or the Y-axis, depending on which side you put it. Putting the phone in a 45 degree angle along the X-axis would give us a value of ±707 on the Z-axis and ±707 on the Y-axis, since gravity cannot affect either axis with its full force (You can easily calculate what the value should be for a certain angle for each axis using the sine and cosine functions). Using the values from the X and Y-axis from the accelerometer, we can determine the position of the phone at any time, and then use that value to move our ship to avoid the incoming asteroids.
So, having accelerometer data for all 3 axes we may figure it out what is horizontal angle of a device.
I'm monitoring a GPS unit which is on it's way from Cape Discovery in Canada, to the North Pole. I need to keep track of the distance travelled and distance remaining each day, so I'm using the Haversine Formula, which I'm told is very accurate for smaller distances.
I'm really bad a Math, but I have a sneaking suspicion that the accuracy depends greatly on the radius of the Earth, and since the universe decided to make Earth out of an oblate spheroid, I have a choice of approximations for Earths radius to choose from.
Since I'm monitoring coordinates very close to the north pole, I'm wondering wether anyone knows which radius is going to provide the most accuracy.
Mean Equatorial: 6,378.1370km
Mean Polar: 6,356.7523
Authalic/Volumetric: 6,371km
Meridional: 6367km
Or any other kind of Radius that anyone knows about?
I'm hoping some maths or cartography whizz might know the answer to this one.
You could approximate the actual radius at the point(s) where you're measuring the distance (provided that you calculate a sequence of relative small distances).
Assuming the earth being an ellipsoid with the main axis a being the mean equatorial radius and the second axis b being the mean polar radius, you can calculate the point on the ellipse represented by these two axes by using the current latidude. The calculation is shown and explained here.
(Note: This ellipse can be thought as a cross section of the earth through the poles and the point where you want to calculate the distance)
This gives you a point q=(qx,qy), the radius at this point being r=sqrt(qx^2+qy^2). That's what I'd use for calculating the Haversine formula.
It doesn't really matter - they are all going to be wrong if you just treat the earth as a sphere. I would probably use the polar since you are mostly going north.