1

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....!

chandru
  • 407
  • 1
  • 5
  • 26
  • If the text boxes were really blank, the coordinate would be set to 0,0 which is in the Atlantic Ocean (not San Francisco). NSLog the values of the text boxes and myCoordinate (after setting its latitude and longitude). –  Nov 22 '13 at 12:50
  • Well, I used the below code, I have written, any way thank u for responding. – chandru Nov 22 '13 at 12:53
  • Can u please check this too,http://stackoverflow.com/questions/20143169/error-in-drawing-polyline-in-ios?noredirect=1#comment30024334_20143169 – chandru Nov 22 '13 at 13:07

2 Answers2

1

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.

Dunes Buggy
  • 1,779
  • 1
  • 21
  • 41
0

I got it,by the following code.

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

Thank u @iRavi

chandru
  • 407
  • 1
  • 5
  • 26