Pergunta

In my app, I am having a map view and two text boxes.
The text boxes contains the coordinates of the annotation.
If I enter the coordinates in those text boxes and press the submit button, an annotation for the corresponding coordinate is plotted.
But if I don't enter any value in the text boxes and press the submit button, an annotation is plotted at san francisco.

- (IBAction)submitButton:(id)sender 
{
myCoordinate.latitude=[latitude_value.text floatValue];
myCoordinate.longitude=[longitude_value.text floatValue];
CLLocationDistance distance=1000;
MKCoordinateRegion newRegion=MKCoordinateRegionMakeWithDistance(myCoordinate,          distance,distance);
[self.mapView setRegion:region animated:YES];
MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = myCoordinate;
[self.mapView addAnnotation:annotation];  

}

The 2 text boxes are latitude_value and longitude_value.
Please help....!

Foi útil?

Solução

Because of empty text, it might be converted to 0.000,0.000 or so, better approach is to check [latitude_value.text isEqualToString:@""] and if not then continue with your task. Let me know if this helps.

I guess if this fails, you can just remove all annotations from the map.

Outras dicas

I got it,by the following code.

if (latitude_value.text==NULL && longitude_value.text==NULL) {
    NSLog(@"nothing to display");
}

Thank u @iRavi

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top