如何使用文本字段设置经度和纬度

How to set longitude and latitude using textfield

如何使用文本字段设置经度和纬度?我曾尝试将我的文本字段设为双文本字段,但它似乎崩溃了。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    mapview.showsUserLocation = YES;

    MKCoordinateRegion region = { {0.0, 0.0}, {0.0,0.0}};
    region.center.latitude = *(myTextField);
    region.center.longitude = *(myTextField1);
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [mapview setRegion:region animated:YES];


    MapPin *ann = [[MapPin alloc] init];
    ann.title = @"Test";
    ann.subtitle = @"test";
    ann.coordinate = region.center;
    [mapview addAnnotation:ann];  
}

我怎样才能使这个工作?

MKPointAnnotation *annonation = [[MKPointAnnotation alloc]init];
CLLocationCoordinate2D mycordinate;
mycordinate.latitude = [self.latitude floatValue];
mycordinate.longitude =[self.longitude floatValue];
annonation.coordinate = mycordinate;
[self.mapview addAnnotation:annonation];

self.latitude 中存储您的纬度值并 在 self.longitude 中存储您的经度值。

试试下面的代码:

只需从 textFields 中获取文本并从文本中设置纬度、经度浮点值。

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
mapview.showsUserLocation = YES;

MKCoordinateRegion region = { {0.0, 0.0}, {0.0,0.0}};
region.center.latitude = [self.myTextField.text floatValue];
region.center.longitude = [self.myTextField1.text floatValue];
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapview setRegion:region animated:YES];


MapPin *ann = [[MapPin alloc] init];
ann.title = @"Test";
ann.subtitle = @"test";
ann.coordinate = region.center;
[mapview addAnnotation:ann];

}