Rani
Rani

Reputation: 3453

How to get dynamic location direction on map in iphone

I am creating a map application.I want that as a person travels from his current location to some other location the same should be simultaneously plotted on the map.how is this possible.Please if anybody have source code regarding this please provide me. Thanks.

Upvotes: 0

Views: 946

Answers (4)

nevan king
nevan king

Reputation: 113747

Here's what you'll need to do:

You want to show a map, so you'll need to add the Mapkit framework and import it. Add an MKMapView and get a reference to it (so you can adjust the map center and region).

Since you want to track the user's location, add the CoreLocation framework and import it. In your view controller, create a new CLLocationManager, set it's relevant properties (since you're tracking a walker, you'll want a high accuracy, around 10-20 meters). Set your view controller as a CLLocationManagerDelegate and implement –locationManager:didUpdateToLocation:fromLocation:. In here, you'll get information about the user's location. You might want to filter it for timestamp, accuracy or other things.

Each time you get a location reading, store it in an array. If you're finding that there are too many readings, use a timer to limit storing readings to every few seconds. You should also set the map's region so that it's centered on the new location.

You can show the points on the map in a couple of ways. The easy way is to add an MKAnnotation object to the mapView's annotations array, using addAnnotation:. You might want to create an annotation view which is just a small dot, instead of the pin.

The second way is to learn how to use MKOverlays, particularly MKPolyline which will draw a line on your map.

Upvotes: 2

visakh7
visakh7

Reputation: 26390

@iPhoneFun's answer is correct. To add to that you can also go through the MKMapView reference which contains the information for plotting user location. Check property userLocation, showsUserLocation, userLocationVisible

Upvotes: 0

Fran Sevillano
Fran Sevillano

Reputation: 8163

In order to draw routes the easiest you can do is make use of MKPolyline class, which is quite straight forward. The only thing is that it only works from iOS SDK 4.0. If you want it to be compatible with iOS 3, you should make use of the MKAnnotation protocol and the MKAnnotationView class. It is a little more complicated but fortunately it is easy to find help. The best tutorial I have found out there is this one. Check it out.

I hope this helps you

Upvotes: 0

V.V
V.V

Reputation: 3094

The GPS of iPhone is so power full that It will automatically identify the current location.

If you want to check then just move out side your office to some other place, even though the Wi-Fi and Sim cards are not available still the GPS will show the perfect location and provides you the exact Latitude and Longitude.

You can use This Code and can get the current location using the GPS of iPhone.

Hope this is what you were needed.

Upvotes: -1

Related Questions