Calculate distance from movement iOS MapKit - ios

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

Related

How to rotate Apple map in driving direction in ios?

I want to rotate apple map based on user's driving direction,
Any idea or solution to rotate map like that way?
I can collect array of last 5-10 moved location, but based on it, Can I calculate heading or anything else to rotate map?

Identify when MKRoutestep finishes

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.

Swift LocationManager Horizontal Accuracy

Is it possible to get location manager to register changes in location of a foot or less? I'd like to tap a button and register one location and move a short distance (foot or less) and tap another button to register that location. I'm trying now with the 13 decimal places provided but I see no difference. When I check the horizontal accuracy I'm only getting 65 meters. I'm indoors. New to this.

How to determine if user is on same road as GPS coordinates

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.

Is There A Way To Get Street View Coordinates After Gesture?

I'm displaying a Street View (GMSPanoramaView) via Google Maps SDK for iOS in an iPhone/iPad app and I need to get the final position of a Street View after the user has navigated around in it using gestures, so that I can restore it to the exact position the user moved it to. This is extremely important to be able to do since the Street View is not accurate and often places an address hundreds of yards away from the actual one requested, forcing the user to tap and zoom to move the Street View in front of it. I don't see any delegate methods or API's to get updated coordinates. I can easily track the heading, pitch, zoom, and FOV via the GMSPanoramaViewDelegate didMoveCamera method, but that does not give me updated coordinates. Thus when I restore the Street View using the last heading, pitch, zoom, and FOV values, the Street View displays at the original location but with the heading, pitch, zoom, and FOV applied, which doesn't display the same position as the user expects. Does anyone know how to get (or track) these coordinates? Thanks!
Implement the panoramaView:(GMSPanoramaView*)view didMoveToPanorama:(GMSPanaorama*)panorama on the delegate.
On the GMSPanorama there's a CLLocationCoordinate2d called coordinate - voila.
EDIT
It also appears that at any point in time to can just get the panorama property from the GMSPanoramaView and get the coordinate from there.

Resources