I am trying to implement a turn by turn navigation system in iOS using MKDirections API. I am able to get the directions of the route and can draw the polyline on the map, and when navigation starts the app start showing the instructions using the MKRouteStep object in Steps array. Now the problem is, since the distance in the MKRouteStep object is the distance that the user covers while traversing the path of the step I am unable to identify how to calculate this distance. Is there any way to calculate this distance ? Currently I am calculating the distance between two coordinates i.e the coordinate when last instruction was shown with the current location of user and if this distance is equal to the distance mentioned in MKRouteStep I am showing the next instruction, due to which it is delaying the instruction to be delivered to user.
If there is any way to identify the coordinate or region where this MKRouteStep ends I can calculate whether the user is in that region or not and then show the next instruction. May be this can work what are your thoughts, but for this how will I know the coordinate or region where this MKRouteStep ends from polyline array of MKRouteStep?
Please suggest if there is any other good solution for this. Any help is highly appreciated.
Thanks.
Since no one has answered to my question I am answering it myself so that it may help someone looking for the same.
So instead of using distance value of MKRouteStep to calculate when to show next instruction, we can use the last coordinate of polyline array provided by MKRouteStep. For example:
MKMapPoint mapPointForEndOfRouteStep = routeStep.polyline[routeStep.polyline.pointCount - 1];
Now you can create a region around it and check whether your current location lies in this region or not.
Related
I'm trying to figure out how I can place an annotation randomly on a road.
I can randomly position an annotation onto a map, but I would like this annotation to be on a road and not in a shopping mall/building/home etc.
Does anyone know the best way I can do this?
One strategy would be to take your random coordinate and then reverse geocode it. That will provide an address closest to your random coordinate. Once reverse geocoded, you can use the result of that process to create your annotation.
In my Xamarin ios app I have to draw the path as user walks,
I am planning to do this by drawing Polyline to a Map view by fetching Lattitude & Longitude from CClocationManager, But I have to deal with N number of Lattitude & Longitude in this case,
Is there any simple approach to do this? In our scenario We won't be knowing the destination , User will Just start a run from a point and we have to track his path on map by drawing a line, How could I do this?
A possible solution could be to save the current last known position, which also represents you endpoint of a polyline. On a location change use it as a starting point for the next polyline. That way you draw the route with multiple polylines piece by piece.
I have an GPS based iPhone application that uses Google Maps. The app simply displayes the users current location on the map and will alert users when they come to within a certain radius of a marked Point on their journey.
For legal reasons I am unable to use turn-by-turn navigation in the app so the app will never know the route the user is taking to get from A to B. All the app does is constantly check current location agains a database of GPS Point coordinates. If the users current location is within e.g. 50 meters of a Point, the user will get a message regarding that Point.
My issue is this:
Each Point has a radius of say 50 meters around it as marked by the large blue circle on the image below.
The user is indicated by small blue dot and the direction of travel is marked by the red arrow. In the image the user has entered the radius of the Point but is not actually on the same road as the Point. The user should only get messages should they be on the same road as the Point and within the radius of the Point.
Is there a way I can determine if the user is on the same road as thePoint when entering that Points radius?
Side Note: The app is working in its current state and I can get messages when entering the radius of a Point.
I have been implementing gps based track and trace apps for a while. The easiest way I see is when you get the event that the point is entering the 50 m radius you do a geolookup meaning you ask the system the address of the long/lat. You compare this (street) with the geolookup of your ref point.
This requires a geolookup service and the user being online.
Instead of using a circle, you should use a rectangle defined when creating each point. Or use both: test rectangle of the street once inside the circle if your rectangle is too approximate. You can find out approximate edges of the rectangle by testing geolookup different point of the circles at the beginning.
I have a path of GPS coordinates that I'm drawing to a map. I need to determine which point of the path the user is currently closest to. I'm able to loop through nearby points on the path and determine which is the closest, but I'm having an issue.
Sometimes the path involves a return trip, so two parts of the path may be parallel.
What is the best way to tell whether the user is on the way out or returning? They may launch my app at any point during the path, and it needs to be able to know what part of the path they're on.
The only solution I can think of is to use the direction they're moving and guess that they must be on whichever part of the path moves in that direction, but it seems like there has to be another way.
For clarification: In the diagram below, how can I determine whether the user is at point A or point B of the path, if I can't assume that my app has been location-aware for the duration of their traveling the path?
Diagram
The solution is a combination of distance checking and direction checking.
First get all positions within a radius of 100m, then sort by distance.
Take the first which does not deviate by more than x degrees of current user direction.
I would like to be able to calculate distance based upon movement, as in user taps a start button and then when they reach their destination they tap a stop button. The app would calculate the actual distance travelled between the two points.
I have the mapkit working in that I can get the start location and the map tracks movement I just need to add in the calculation of distance.
Is this possible? If so any sample code would be much appreciated.
well what you could do is, record the user's coordinates when he hits start. The record his coordinates when he hits stop. Then you could use the CoreLocation framework to calculate the distance between the two points.
distance = [newLocation distanceFromLocation:oldLocation];
EDIT
I see now that you want the distance actually travelled by the person. I know that in the new IOS you can make use of the direction functionality, so what you could do is record the distance traveled every time the user changes the direction, and then add everything up when they hit STOP
EDIT
you can check out some of apple's sample code