Search Results

Search found 6 results on 1 pages for 'krismutt'.

Page 1/1 | 1 

  • Zoom to fit region for all annotations - ending up zooming in between annotations

    - by Krismutt
    Hey everybody!! I have a problem with fitting all my annotations to the screen... sometimes it shows all annotations, but some other times the app is zooming in between the two annotations so that none of them are visible... I want the app to always fit the region to the annotations and not to zoom in between them... what do I do wrong? if ([mapView.annotations count] == 2) { CLLocationCoordinate2D SouthWest = location; CLLocationCoordinate2D NorthEast = savedPosition; NorthEast.latitude = MAX(NorthEast.latitude, savedPosition.latitude); NorthEast.longitude = MAX(NorthEast.longitude, savedPosition.longitude); SouthWest.latitude = MIN(SouthWest.latitude, location.latitude); SouthWest.longitude = MIN(SouthWest.longitude, location.longitude); CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:SouthWest.latitude longitude:SouthWest.longitude]; CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:NorthEast.latitude longitude:NorthEast.longitude]; CLLocationDistance meter = [locSouthWest distanceFromLocation:locNorthEast]; MKCoordinateRegion region; region.span.latitudeDelta = meter / 111319.5; region.span.longitudeDelta = 0.0; region.center.latitude = (SouthWest.latitude + NorthEast.latitude) / 2.0; region.center.longitude = (SouthWest.longitude + NorthEast.longitude) / 2.0; region = [mapView regionThatFits:region]; [mapView setRegion:region animated:YES]; [locSouthWest release]; [locNorthEast release]; } Any ideas? NEW CODE (by Satya) -(void)zoomToFitMapAnnotations:(MKMapView*)mapview{ if([mapview.annotations count] == 0) return; CLLocationCoordinate2D topLeftCoord; topLeftCoord.latitude = -90; topLeftCoord.longitude = 180; CLLocationCoordinate2D bottomRightCoord; bottomRightCoord.latitude = 90; bottomRightCoord.longitude = -180; for(FSMapAnnotation* annotation in mapView.annotations) { topLeftCoord.longitude = fmin(topLeftCoord.longitude, location.longitude); topLeftCoord.latitude = fmax(topLeftCoord.latitude, location.latitude); bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, savedPosition.longitude); bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, savedPosition.latitude); } MKCoordinateRegion region; region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5; region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5; region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides region = [mapView regionThatFits:region]; [mapView setRegion:region animated:YES]; } Can't get it to work... FSMapAnnoation is undeclared... how do I fix this?

    Read the article

  • Zooming out to fit all annotations in MapKit

    - by Krismutt
    Hey everybody!! I wanna zoom out so that all my annotations(my location and one more annotation) fit to the screen...what do I do wrong?? I get the following warning: "'getDistanceFrom:' is deprecated".... -(void)viewDidLoad { [super viewDidLoad]; mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; mapView.showsUserLocation = TRUE; mapView.delegate = self; mapView.mapType = MKMapTypeStandard; mapView.zoomEnabled = YES; mapView.scrollEnabled = YES; mapView.userInteractionEnabled = YES; [mapView.userLocation setTitle:@"Nuvarande plats"]; [mapView.userLocation setSubtitle:@"Du är här"]; [self.view insertSubview:mapView atIndex:0]; self.locationManager = [[[CLLocationManager alloc] init] autorelease]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager startUpdatingLocation]; [mapView release]; } -(void) locationManager: (CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ NSLog (@"Position uppdateras" ); location = newLocation.coordinate; if (friZoom) { MKCoordinateRegion region; region.center.latitude = location.latitude; region.center.longitude= location.longitude; MKCoordinateSpan span; span.latitudeDelta = 0.01; span.longitudeDelta = 0.01; region.span = span; [mapView setRegion:region animated:TRUE];} } - (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)knappnal { if ([knappnal isKindOfClass:MKUserLocation.class]) { return nil; } MKPinAnnotationView *knappnalView = (MKPinAnnotationView*)[mapview dequeueReusableAnnotationViewWithIdentifier:@"annot"]; if (!knappnalView) { knappnalView = [[[MKPinAnnotationView alloc] initWithAnnotation:knappnal reuseIdentifier:@"annot"] autorelease]; knappnalView.pinColor = MKPinAnnotationColorRed; knappnalView.animatesDrop = YES; knappnalView.canShowCallout = YES; } else { knappnalView.annotation = knappnal; } return knappnalView; } - (IBAction)storeLocationInfo:(id) sender{ SparaPosition *position=[[SparaPosition alloc] initWithCoordinate:location]; [mapView addAnnotation:position]; savedPosition = location; } - (IBAction)visaPosition:(id)sender{ CLLocationCoordinate2D southWest =location; CLLocationCoordinate2D northEast =savedPosition; southWest.latitude = MIN(southWest.latitude, location.latitude); southWest.longitude = MIN(southWest.longitude, location.longitude); northEast.latitude = MAX(northEast.latitude, savedPosition.latitude); northEast.longitude = MAX(northEast.longitude, savedPosition.longitude); CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude]; CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude]; CLLocationDistance meters = [locSouthWest getDistanceFrom:locNorthEast]; MKCoordinateRegion region; region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0; region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0; region.span.latitudeDelta = meters / 111319.5; region.span.longitudeDelta = 0.0; region = [mapView regionThatFits:region]; [mapView setRegion:region animated:YES]; [locSouthWest release]; [locNorthEast release]; } Would really appreciate an answer!

    Read the article

  • Storing an subtitle on an annotation with NSUserDefualts

    - by Krismutt
    Hey everybody! Basically: what i try to do is to save the street address of an annotation so that when I quit the application and launch it again the street address still will be there...see the following code: SavePosition.m -(NSString *)subtitle{ if (!subtitle) { return @"Ingen gata i närheten"; } else { return subtitle; } } -(NSString *)title{ return @"Sparad Position"; } -(id)initWithCoordinate:(CLLocationCoordinate2D) coor{ self.coordinate=coor; NSLog(@"%f,%f",coor.latitude,coor.longitude); return self; } - (void)setCoordinate:(CLLocationCoordinate2D)koor { MKReverseGeocoder *geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:koor] autorelease]; geocoder.delegate = self; coordinate = koor; [geocoder start]; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { NSLog(@"fail %@", error); } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { self.subtitle = [placemark.addressDictionary valueForKey:@"Street"]; } -(void)applicationWillTerminate:(UIApplication *)application { NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults]; [userDef setValue:subtitle forKey:@"SavedAddress"]; [userDef setBool:YES forKey:@"Street"]; [userDef synchronize]; } @end mainViewController.m -(void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults]; if ([userDef boolForKey:@"sparadKoordinat-existerar"]) { CLLocationCoordinate2D savedCoordinate; savedCoordinate.latitude = [userDef doubleForKey:@"sparadKoordinat-latitud"]; savedCoordinate.longitude = [userDef doubleForKey:@"sparadKoordinat-longitud"]; SparaPosition *position=[[SparaPosition alloc] initWithCoordinate:savedCoordinate]; [mapView addAnnotation:position]; savedPosition = savedCoordinate; raderaSparad.enabled=YES; skickaMaps.enabled=YES; mStoreLocationButton.enabled=NO; friZoom = NO; NSString *savedAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"SavedAddress"]; if (savedAddress) { savedAddress.subtitle = [userDef valueForKey:@"Street"]; // what code should I add here? } MKCoordinateRegion region; region.center.latitude = savedCoordinate.latitude; region.center.longitude= savedCoordinate.longitude; MKCoordinateSpan span; span.latitudeDelta = 0.01; span.longitudeDelta = 0.01; region.span = span; region = [mapView regionThatFits:region]; [mapView setRegion:region animated:YES]; [mapView setRegion:region animated:TRUE]; }

    Read the article

  • Reverse geocode coordinates to street address and setting as subtitle in annotation?

    - by Krismutt
    Hey everybody! Basically I wanna reverse geocode my coordinates for my annotation and show the address as the subtitle for the annotation. I just cant figure out how to do it... savePosition.h #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> #import <MapKit/MKReverseGeocoder.h> #import <AddressBook/AddressBook.h> @interface savePosition : NSObject <MKAnnotation, MKReverseGeocoderDelegate> { CLLocationCoordinate2D coordinate; } @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; -(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate; - (NSString *)subtitle; - (NSString *)title; @end savePosition.m @synthesize coordinate; -(NSString *)subtitle{ return [NSString stringWithFormat:@"%f", streetAddress]; } -(NSString *)title{ return @"Saved position"; } -(id)initWithCoordinate:(CLLocationCoordinate2D) coor{ coordinate=coor; NSLog(@"%f,%f",coor.latitude,coor.longitude); return self; MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate]; geocoder.delegate = self; [geocoder start]; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{ NSString *streetAddress = [NSString stringWithFormat:@"%@", [placemark.addressDictionary objectForKey:kABPersonAddressStreetKey]]; } @end any ideas?? Thanks in advance!

    Read the article

  • Storing and loading a subtitle of an annotation with NSUserDefualts

    - by Krismutt
    Happy new year everybody! Basically, what I try to do is to save a subtitle to an annotation when the application terminates. When the application starts again I want this stored subtitle to show up in the callout of the annotation again. What am I doing wrong? I just can't get it to work... storeLocation.m - (void)setCoordinate:(CLLocationCoordinate2D)coor { MKReverseGeocoder *geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:coor] autorelease]; geocoder.delegate = self; coordinate = coor; [geocoder start]; NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults]; [userDef setValue:subtitle forKey:@"SavedAddress"]; [userDef synchronize]; NSLog(@"Sparade adress"); } mainViewController.m -(void)viewDidLoad { NSString *savedAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"SavedAddress"]; if (savedAddress) { // what code should I add here // so that the subtitle shows up // when the application launches? } } Would really appreciate some help with this one... Thanks in advance!

    Read the article

  • Updating the getDistanceFrom between two annotations in MapKit

    - by Krismutt
    Hey everybody! I wanna have a UILabel that shows the distance between two annotations... but how do I get it to update the distance each time the current location is updated (location)?? CLLocationCoordinate2 savedPlace = savedPosition; CLLocationCoordinate2D currentPlace = location; CLLocation *locCurrent = [[CLLocation alloc] initWithLatitude:currentPlace.latitude longitude:currentPlace.longitude]; CLLocation *locSaved = [[CLLocation alloc] initWithLatitude:savedPlace.latitude longitude:savedPlace.longitude]; CLLocationDistance distance = [locSaved distanceFromLocation:locCurrent]; [showDistance setText:[NSString stringWithFormat:@"%g", distance]]; Thanks in advance!

    Read the article

1