pulsating blue circle and dot in mapkit - iPhone SDK - iphone

How can I add the "Pulsating blue circle" in my gps application.
Currently i am fetching my current location by CCLocationManager.
I am using mapView.showsUserLocation = True, but this only display a pin at my current location.
How can i get that "blue circle" as in the default maps app.
update: many app does this. for example - Realtor.com
Thanks

Implement the delegate method:
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation: (id<MKAnnotation>)annotation
and return nil if if (annotation == mv.userLocation). This tell the MKMapView to use whatever standard annotation it deems appropriate.

if (annotation == Current Location){
return nil;
}else{
}

Related

User location appearing when setshowsuserlocation = NO

I created a custom view for user location using :
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
if([annotation class]==[MKUserLocation class])
{
//my code to return the pin
}
else
{
//code for custom pin
}
After some user action i update setShowsUserLocation to NO for the mapview. Then I start core location controller which uses a different custom pin view to track user location. THe original pin dissappears for sometime but then reappears later on when i drag or pinch to zoom on the map. while debugging i saw that it enters the if condition above was called inspite of setShowsUserLocation being set to no.

User Location Strange Issue

I have all concept of Maps how it works but I am stuck in very strange issue.
As soon as open my Map Controller my default blue is visible (MKUserLocation) but when I am loading custom pins (IVMyLocation, Annotation class), default pin disappear.
I am properly managing removing of custom pins so that default pin shouldn't disappear like
for (id<MKAnnotation> annotation in _mapView.annotations) {
if([annotation isKindOfClass:[IVMyLocation class]])
[_mapView removeAnnotation:annotation];
}
But still my default pin is disappearing. Its only visible first time.
NOTE: Its working fine in Xcode4 simulator its disappearing in only device
You should return nil for the MKUserLocation in mapView:viewForAnnotation:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// etc
This allows the default blue dot to show.
Reduce your objects count. Helped for me.

iphone blue dot AND pin at same time -

please help, this question has been asked so many times before, but peoples suggestions have no effect on my outcome, all i want, is the pin and blue circle (Accuracy) to be shown on the map, here is my implementation. - oh, im using an iPhone device - im not in the simulator
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
NSLog(#"View for Annotation is called");
if (NSClassFromString(#"MKUserLocation")==[annotation class]) {
return nil;
}
if (annotation == mapView.userLocation) {
return nil;
}
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton * btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = btn;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
pinDropped = TRUE;
return annView;
}
cheers in advance.... bloody thing
If you're using the Simulator then you're likely encountering the not-well-known difference in the way that CoreLocation and MapKit figure your current position.
 
In the Simulator
CoreLocation will always use Apple's headquarters in Cupertino, California, USA as your current location. This is where the blue dot will always appear on the map.
MapKit will always use something approximating your actual current location using Apple's database of IP address and WiFi hotspot information. This is where the map will center if you tell it to use your current location.
As a result, the map will center on your current location but the blue dot will be over in Cupertino.
 
On an iOS Device
CoreLocation puts the blue dot on something approximating your actual current location.
MapKit centers the map on something approximating your actual current location.
As a result you'll see the blue dot in the center of the map when using an actual iOS device.
 
This bit of knowledge can save a lot of stress. :)
just in case someone was wondering, this also works:
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
This works in my code
if(annotation == mapView.userLocation){
return nil;
}
Try that and let us know
make sure implemented [mapview addAnnotation:annotation];
thanks Anna for the reminder.

Placing a blue dot (user location) Only using CLLocationManager

I've read through countless posts here on stack and apple's docs and can't find anything to solve this problem.
The issue is if you set mapView.showsUserLocation = YES, then MapKit will start making it's own GPS queries to your phone.
From apple docs:
Setting this property to YES causes
the map view to use the Core Location
framework to find the current
location. As long as this property is
YES, the map view continues to track
the user’s location and update it
periodically.
If you also want to use CLLocationManager, then when you make a call to [mylocationmanager startUpdatingLocation], then you are making a second GPS query on your phone.
Now you have 2 separate processes asking for GPS location.
Not a problem on the simulator, but if you try it on a real phone it will take a very very long time to get the GPS location. It is also inconsistent 10seconds - 1 minute, whereas if you turn off mapView.showsUserLocation it takes 2-3 seconds very consistently.
In general it seems like a very bad practice to use both.
For flexibility and control, I'd rather use CLLocationManager, but if you don't set mapView.showsUserLocation = YES, then you don't get the blue dot!
I tried the usual overwrite annotation methods: eg:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
if ([annotation isKindOfClass:MKUserLocation.class]) {
//it's the built-in user location annotation, return nil to get default blue dot...
return nil;
}
//handle your custom annotations...
}
But it doesn't work, most probably because there is never a call to actually place a user annotation on the map.
So does anyone have a solution to only use CLLocationManager to place the user's location on the map?
Just overriding the viewForAnnotation method isn't enough, you first have to add you annotations to the map by calling
[mapView addAnnotation:annotationObject];
Your annotationObject can be an instance of any class that implements the MKAnnotation protocol. You can find the details in the MapKit Guide in the Annotating apps section.
If you need to show just blue dot around your location (accuracy), you can do it like this:
MKCircle *accuracyCircle;
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// when you want update your position and accuracy
[self.mapView removeOverlay:accuracyCircle];
accuracyCircle = [MKCircle circleWithCenterCoordinate:newLocation.coordinate
radius:newLocation.horizontalAccuracy];
[self.mapView addOverlay:accuracyCircle];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if([overlay isKindOfClass:[MKCircle class]])
{
MKCircleRenderer * circleRenderer = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleRenderer.fillColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.2];
return circleRenderer;
}
return nil;
}

showsUserLocation does not display blue dot in iPhone 4.0

So, I've created a CLLocationManager, called it to start updating, set mapView.showsUserLocation to YES, and returned nil for the userLocation annotation.
Here are some snippets from my code in my UIMapViewController:
- (void)viewDidLoad
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D userCoordinate = locationManager.location.coordinate;
[map setCenterCoordinate:userCoordinate animated:YES];
[map setShowsUserLocation:YES];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *mapIconView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:#"mapIconView"];
// Don't mess with the user location annotation
if (annotation == mapView.userLocation)
return nil;
// etc.
}
This all seems pretty straightforward. Everything works fine--the map zooms to my location as it should, and I've confirmed that all the methods are called as expected--but no blue dot. Can't get the blue dot for the life of me, no matter where or how many times I say
mapView.setUserLocation = YES;
What am I missing here?
When I do this, rather than checking annotation like you have, I do something along the lines of:
if([annotation class] == MKUserLocation.class) {
return nil;
}
I had this same problem where the blue dot wouldn't appear. Turns out it was appearing, just not where I thought it was.
Similarly to my issue, your code looks like it's both processing location updates and asking the MKMapView to track the user location. Note that in the simulator, these are two different locations! When the MKMapView is tracking the user location in the simulator, it gives you the location of Apple in Cupertino, CA, regardless of your "actual" location.
Using this code and letting the MKMapView track the location for your delegate instead of tracking the location yourself can reveal the blue dot:
- (void)mapView:(MKMapView *)theMapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
[theMapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}
You'll probably want to zoom in a bit. I used the handy code from this blog entry to do that: Set the Zoom Level of an MKMapView
It's mapView.showUserLocation = YES;
You seem to have used the wrong statement 'set' instead of 'show'.
And FYI, you don't have to mess with the location manager just to get the userlocation. Corelocation automatically gets fired when you set mapview.showUserLoction = YES and load the map.
Hope it helps :)
Make sure that you are not removing all annotations from the map anywhere:
e.g. [mapView removeAnnotations:mapView.annotations]
If you are using the iOS simulator, then you can't see the blue dot. I had the exact same problem and when I started to try my software with the real hardware the blue dot showed up!