I have a problem with MKCoordinateRegionMakeWithDistance.
I try to specify the distance value via a slider in the preferences of my iPad App.
When I put in more that 963 as int or float, the mapView don't apply the value and takes it's own value.
Is there any maximum value or can I edit the MKMapView that it will take values about 10.000 meters?
Thanks, kind regards, Julian
Edit
Here's some code on request:
// PreferencesView
- (IBAction)changeZoomDidEnd:(UISlider *)sender
{
[[NSUserDefaults standardUserDefaults] setInteger:[sender value] forKey:#"defaultZoom"];
}
// MapView
- (IBAction)zoomToLocation:(id)sender
{
defaultZoom = [[[NSUserDefaults standardUserDefaults] valueForKey:#"defaultZoom"] intValue];
[mapView setRegion:MKCoordinateRegionMakeWithDistance(mapView.userLocation.coordinate, defaultZoom, defaultZoom) animated:YES];
}
Related
I want to have UITextField with multiple lines, after a quick google on this issue I found that I should use TextView so I did switch my code to use UITextView when I want multiple lines. My View still have other one line textField that I want to keep.
To make my TextView looks like TextField, I had to add code to set border and radius, but they look a little bit different on iOS7. Does anyone know:
what is the color for the UITextField border? when both enabled and disabled so I can sent my textview to match it.
what is radius of the corner of TextField.
what is the background color for UITextField when it is disabled[attached picture shows the text field has lighter shade of grey when it is disabled]? so i can set my text view to the same color when i disable user interaction.
If there is away to keep using textfield for multiline text, I am all ears and i switch to use it.
Best Regards,
I use this:
textView.layer.borderColor = [[UIColor colorWithRed:215.0 / 255.0 green:215.0 / 255.0 blue:215.0 / 255.0 alpha:1] CGColor];
textView.layer.borderWidth = 0.6f;
textView.layer.cornerRadius = 6.0f;
little differences in the params make it looks more like UITextField(I hope).
I use this:
#import <QuartzCore/QuartzCore.h>
-(void) textViewLikeTextField:(UITextView*)textView
{
[textView.layer setBorderColor:[[UIColor colorWithRed:212.0/255.0
green:212.0/255.0
blue:212.0/255.0
alpha:1] CGColor]];
[textView.layer setBorderWidth:1.0f];
[textView.layer setCornerRadius:7.0f];
[textView.layer setMasksToBounds:YES];
}
and get a good resut.
I have a small subclass of UITextView that gives in iOS 7 the same look as the UITextField
The interface is empty:
#interface MyTextView : UITextView
#end
The implementation overwrites the initialization and the setter of the 'editable' property:
#implementation MyTextView
//================================================================================
- (id) initWithFrame: (CGRect) frame
{
self = [super initWithFrame:frame];
if (self)
{
[self commonInit];
}
return self;
}
//================================================================================
- (id) initWithCoder: (NSCoder *) aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self commonInit];
}
return self;
}
//================================================================================
- (void) commonInit
{
self.layer.borderWidth = 1.0f;
self.layer.borderColor = [[UIColor colorWithRed:232.0/255.0
green:232.0/255.0 blue:232.0/255.0 alpha:1] CGColor];
self.layer.cornerRadius = 6;
}
//================================================================================
- (void) setEditable: (BOOL) editable
{
[super setEditable:editable];
if (editable)
{
self.backgroundColor = [UIColor whiteColor];
}
else
{
self.backgroundColor = [UIColor colorWithRed:250.0/255.0
green:250.0/255.0 blue:250.0/255.0 alpha:1];
}
}
//================================================================================
#end
This is the closest I got with enabled UITextView
[yourTextView.layer setBorderColor:[[[UIColor lightGrayColor] colorWithAlphaComponent:0.2] CGColor]];
[yourTextView.layer setBorderWidth:2.0];
yourTextView.layer.cornerRadius = 5;
yourTextView.clipsToBounds = YES;
yourTextView.textColor = [UIColor lightGrayColor];
Can anybody help me please? I'm new to xcode and am baffled by what I think is a small problem. For some reason the first time my map is opened from my initial view controller the pin is dropped but the map does not zoom to the correct region even though the latitude and longitude are correct.
When I go back to the first view controller and launch it again the zoom works.
My code is in the view controllers implementation file under viewdidload.
-(void)viewDidLoad {
[super viewDidLoad];
NSLog(#"lat in map %#", eventLat);
NSLog(#"long in map %#", eventLong);
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = [eventLat doubleValue];
region.center.longitude = [eventLong doubleValue];
region.span.latitudeDelta = 0.01f;
region.span.longitudeDelta = 0.01f;
[mapview setRegion:region animated:YES];
MMAnnotate *ann = [[MMAnnotate alloc] init];
ann.title = #"Test Title";
ann.subtitle = #"Test Subtitle";
ann.coordinate = region.center;
[mapview addAnnotation:ann];
}
You should try doing that in viewDidAppear instead. If you're prepared for it to zoom to that location every time the view appears. viewDidLoad is too early in the mapview cycle.
This is a little strange, but I have been trying to find a solution for 2 days straight, to set the map region but nothing seems to work
Here is my code :
-(void)viewWillAppear:(BOOL)animated{
//[self step1locationupdate];
Maplocation.showsUserLocation=YES;
MKCoordinateRegion mapRegion;
mapRegion.center.longitude=self.currentProduct.shop.longcoordinate;
mapRegion.center.latitude=self.currentProduct.shop.latcoordinate;
NSLog(#"The USer Location are :%f",mapRegion.center.latitude);
mapRegion.span.latitudeDelta= 2;
mapRegion.span.longitudeDelta= 2;
[Maplocation setRegion:mapRegion animated:YES];
NSLog(#"The USer Location are :%f %f",Maplocation.userLocation.coordinate.latitude,Maplocation.userLocation.coordinate.longitude);
}
The NSLog for malocation.userlocation.coordinate are always 0 when it starts.
The same code I have added it into the viewDidLoad part & also there was no difference
Kindly help
I think you need to initialize your MKCoordinateRegion before you start using it. Something like 'MKCoordinateRegion mapRegion = MKMakeRegionWithCoordinates(......'
Well I have saved the above method in a (void) method , then I have fired it after 5 Sec from viewWillAppear method.
-(void)viewWillAppear:(BOOL)animated{
[self performSelector:#selector(updatecurrentLocation) withObject:nil afterDelay:5];
}
-(void)updatecurrentLocation{
Maplocation.showsUserLocation=YES;
MKCoordinateRegion mapregion;
mapregion.center=Maplocation.userLocation.coordinate;
mapregion.span.latitudeDelta = 2;
mapregion.span.longitudeDelta = 2;
[Maplocation setRegion:mapregion animated: YES];
}
That is it folks :)
I am trying to find a way to do a zoom in and out via a button. If I put code within the method didAddAnnotationViews, it will set the initial zoom perfectly. I tried to get the zoom to change with the code below, but it keeps on crashing saying:
Unrecognized Selector sent to Instance
How can I run this in an IBAction?
-(IBAction)ZoomIn:(MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mv centerCoordinate:(CLLocationCoordinate2D)location
{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.05;
span.longitudeDelta=0.05;
location = mv.userLocation.coordinate;
location = mv.userLocation.location.coordinate;
region.span=span;
region.center=location;
[mv setRegion:region animated:TRUE];
[mv regionThatFits:region];
};
My issue was that I was trying to pass in the MapView in the IBAction line which I couldnt do. It did not know what to do with it. I referenced my MapView in the code instead of trying to pass it in the method...
CLLocationCoordinate2D location;
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=1.00;
span.longitudeDelta=1.00;
location = self.myMap.userLocation.coordinate;
location = self.myMap.userLocation.location.coordinate;
region.span=span;
region.center=location;
[self.LightUpMap setRegion:region animated:TRUE];
[self.LightUpMap regionThatFits:region];
You can put this is any IBAction method now and it will zoom in to the map.
-(void)zoomOut:btnMinus
{
MKCoordinateSpan span = mapView.region.span;
span.latitudeDelta = span.latitudeDelta * 2;
span.longitudeDelta = span.longitudeDelta * 2;
region.span=span;
[mapView setRegion:region animated:YES];
for(int j=2;j<count;j++)
{ places[j]=1;}
[self filterAnnotations];
}
Sure this is something simple as I'm just starting with the maps. I already have a map showing one location, but when I've added a second anotation the map stays zoomed all the way out rather than going to my locations. The pins are there when I zoom in, so I know that bit's working.
Code snippets:
- (void)viewDidLoad
{
...
...
...
// Set coordinates for our position
CLLocationCoordinate2D location;
location.latitude = [self.lat doubleValue];
location.longitude = [self.lon doubleValue];
// Add the annotation to our map view
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc]
initWithTitle:self.placename
andSubtitle:self.subtitle
andCoordinate:location];
[self.mapView addAnnotation:newAnnotation];
[newAnnotation release];
// Set coordinates for our second position
CLLocationCoordinate2D amenitylocation;
amenitylocation.latitude = self.latitude;
amenitylocation.longitude = self.longitude;
// Add the annotation to our map view
MapViewAnnotation *amenityAnnotation = [[MapViewAnnotation alloc]
initWithTitle:self.callouttitle
andSubtitle:self.calloutsubtitle
andCoordinate:amenitylocation];
[self.mapView addAnnotation:amenityAnnotation];
[amenityAnnotation release];
[super viewDidLoad];
}
#pragma mark - MKMapView Delegates
// When a map annotation point is added, zoom to it (1500 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
[mv setRegion:region animated:YES];
[mv selectAnnotation:mp animated:YES];
}
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id<MKAnnotation>)annotation
{
if(mapView.userLocation==annotation)
{
return nil;
}
NSString *identifier = #"IDENTIFIER";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(annotationView==nil)
{
annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]autorelease];
annotationView.pinColor=MKPinAnnotationColorPurple;
annotationView.canShowCallout=YES;
}
return annotationView;
}
I'd appreciate any pointers.
Also, am I right in thinking I'll have to make custom callouts if I want more than one to appear on the map at the same time?
Sorry, found the answer - I didn't have the MKMapView delegate linked to File's Owner in IB, although I do have in my header file. Linked that up and it's working.