开发者

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 shoul开发者_StackOverflow社区d be simultaneously plotted on the map.how is this possible.Please if anybody have source code regarding this please provide me. Thanks.


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.


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


@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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜