Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to represent a constantly moving signal on a MapView?

Tags:

ios

mkmapview

Im just getting into MapViews on iOS, and want to show a car continuously moving as a blue dot. Would this be considered a map annotation?

like image 339
jfisk Avatar asked Jan 01 '26 03:01

jfisk


1 Answers

Yes. As an example check out the in Simulator Debug > Location > City Bike Ride . It does a slow loop round San Francisco(?)

To listen to updates implement in your Mapview delegate

- (void)mapView:(MKMapView *)amapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"im here! - %f,%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude); 


}

and to adjust the annotation implement

- (MKAnnotationView *) mapView:(MKMapView *)amapView viewForAnnotation:(id <MKAnnotation>) annotation{

    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        return nil;
    }
    NSLog(@"annotation = %@",((NSObject *)annotation));
    MKAnnotationView *annView;

    annView = [amapView dequeueReusableAnnotationViewWithIdentifier:@"currentloc"];

    if(!annView)
    {
        annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"] autorelease];
        ((MKPinAnnotationView *)annView).pinColor = MKPinAnnotationColorGreen;
        ((MKPinAnnotationView *)annView).animatesDrop=TRUE;
        annView.canShowCallout = YES;
        annView.calloutOffset = CGPointMake(-5, 5);
        annView.draggable = YES;
    }
    return annView;
}

The snip I have put in just goes with the default blue dot with accuracy circle by returning nil for MKUserLocation but your implementation may be different.

like image 131
Warren Burton Avatar answered Jan 03 '26 18:01

Warren Burton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!