Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use car image for location annotation

  • Loading branch information...
commit bca965a138313c23e2214806a5850c6ebb779f7a 1 parent 90baf70
@markwj markwj authored
View
BIN  ....xcodeproj/project.xcworkspace/xcuserdata/mark.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
41 apps/iOS/ovms/ovmsLocationViewController.m
@@ -42,7 +42,30 @@ - (void)didReceiveMemoryWarning
-(void) updateLocation
{
- [self displayMYMap];
+ CLLocationCoordinate2D location = [ovmsAppDelegate myRef].car_location;
+
+ MKCoordinateRegion region = myMapView.region;
+ if ( (region.center.latitude != location.latitude)&&
+ (region.center.longitude != location.longitude) )
+ {
+ // Remove all existing annotations
+ for (int k=0; k < [myMapView.annotations count]; k++)
+ {
+ if ([[myMapView.annotations objectAtIndex:k] isKindOfClass:[TeslaAnnotation class]])
+ {
+ [myMapView removeAnnotation:[myMapView.annotations objectAtIndex:k]];
+ }
+ }
+
+ TeslaAnnotation *pa = [[TeslaAnnotation alloc] initWithCoordinate:location];
+ pa.name = @"EV915";
+ pa.description = [NSString stringWithFormat:@"%f, %f", pa.coordinate.latitude, pa.coordinate.longitude];
+ [myMapView addAnnotation:pa];
+ self.m_car_location = pa;
+
+ region.center=location;
+ [myMapView setRegion:region animated:YES];
+ }
}
#pragma mark - View lifecycle
@@ -67,7 +90,7 @@ - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationItem.title = [ovmsAppDelegate myRef].sel_label;
- [self updateLocation];
+ [self displayMYMap];
}
- (void)viewDidAppear:(BOOL)animated
@@ -125,7 +148,7 @@ -(void)displayMYMap
[myMapView addAnnotation:pa];
self.m_car_location = pa;
}
-
+
[myMapView setRegion:region animated:YES];
[myMapView regionThatFits:region];
}
@@ -140,13 +163,15 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapView
if([annotation isKindOfClass:[TeslaAnnotation class]]){
//Try to get an unused annotation, similar to uitableviewcells
- MKAnnotationView *annotationView=[mapView dequeueReusableAnnotationViewWithIdentifier:teslaAnnotationIdentifier];
+// MKAnnotationView *annotationView=[mapView dequeueReusableAnnotationViewWithIdentifier:teslaAnnotationIdentifier];
//If one isn't available, create a new one
- if(!annotationView){
- annotationView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:teslaAnnotationIdentifier];
+// if(!annotationView){
+ MKAnnotationView *annotationView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:teslaAnnotationIdentifier];
//Here's where the magic happens
- annotationView.image=[UIImage imageNamed:@"teslapin.png"];
- }
+ annotationView.image=[UIImage imageNamed:[ovmsAppDelegate myRef].sel_imagepath];
+ annotationView.contentMode = UIViewContentModeScaleAspectFill;
+ annotationView.bounds = CGRectMake(0, 0, 32, 32);
+// }
return annotationView;
}
return nil;
Please sign in to comment.
Something went wrong with that request. Please try again.