3

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?

enter image description here

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Illep
  • 16,375
  • 46
  • 171
  • 302

1 Answers1

7

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.

Community
  • 1
  • 1
  • Thanks, Is there anyway where i could get the location as in latitude and longitude of the user location (the location of the blue-ball) ? – Illep Oct 02 '11 at 15:58
  • Sorry - I forgot to mention that you will need to @synthesize locationManager in the .m file. –  Oct 02 '11 at 16:10
  • Will i get the location (latitude and longitude ) of Cupertio, with the iPhone Simulator? – Illep Oct 02 '11 at 16:15
  • I don't think so - I'm 99% sure you will need to connect to a device in order to get that information. It worth trying though as I may be wrong. –  Oct 02 '11 at 16:21
  • You could alway try hard coding the location for the time being, then when you're happy it's working the way you want you could switch it back so that it picks up the users GPS coordinates... –  Oct 02 '11 at 16:22