开发者

iOS maps GPS location implementing blue-ball location and arrow sign on the map

1.) I need to have a blue ball circle/location dot on a map开发者_运维知识库 as shown below.

  • What is it called?
  • How can I implement it?

iOS maps GPS location implementing blue-ball location and arrow sign on the map

2.) How do I get the arrow on the pop-up screen as below?

iOS maps GPS location implementing blue-ball location and arrow sign on the map


I think what you're after is the MKMapView; if so you just need to add it in interface builder and there is an option (checkbox) in the Attributes Inspector panel that allows you to 'Shows users location'. By checking that box it will make the blue dot appear on the map (if you're using the iPhone Simulator it will only show up as Cupertio).

Theres lots of simple tutorials on getting started with map views for iPhone. Here is a pretty good one. If you don't like it then I suggest you Google 'MkMapView tutorials' and you should find plenty of useful information.

In order to get the location of the user (latitude & longitude) you will need to do a few things:

1) Make sure you've imported the CoreLocation framework (CoreLocation.framework)

2) You need add the following to your .h file:

#import <CoreLocation/CoreLocation.h>

@interface exampleViewController : UIViewController <CLLocationManagerDelegate>
{
    CLLocationManager *locationManager;
}

@property(nonatomic, retain)CLLocationManager *locationManager;

3) You need to add the following to your .m file (wherever is appropriate for your app)

This part will create an instance of the CLLocationManager:

 self.locationManager = [[CLLocationManager alloc] init];
 locationManager.delegate = self;
 locationManager.desiredAccuracy = kCLLocationAccuracyBest;
 [locationManager startUpdatingLocation];

You can then get the current latitude & longitude using the delegate method:

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
           fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"New latitude: %f", newLocation.coordinate.latitude);
    NSLog(@"New longitude: %f", newLocation.coordinate.longitude);
}

You should also look at this existing question and this one too, I think it should help you with the second part of your question.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜