繁体   English   中英

如何设定的经纬线采用文本框

[英]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存储您的经度值。

请尝试以下代码:

刚刚获得来自文本字段和组纬度,从文本经度浮点值的文本。

- (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];

}

latitude,longitude从textFields文本转换为float值,因为您需要float值。 例如: [textField.text floatValue]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM