gpt4 book ai didi

iphone - 您可以根据地址在 Mapview 中创建注释吗?

转载 作者:行者123 更新时间:2023-11-28 22:44:41 24 4
gpt4 key购买 nike

我今天“用谷歌搜索”了这个问题几次,但都没有成功。我想知道是否可以从地址而不是使用 lat/Long 方法在 Mapview 中创建注释。我当前的代码如下。

//1. Create a coordinate for use with the annotation
CLLocationCoordinate2D Sharon;
Sharon.latitude = 38.952223;
Sharon.longitude = -77.193646;

Annotation *myAnnotation = [Annotation alloc];
myAnnotation.coordinate = Sharon;
myAnnotation.title = @"Sharon Lodge #327";
myAnnotation.subtitle = @"McLean, VA";

最佳答案

这样试试,

NSString *location = "some address, state, and zip";
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

MKCoordinateRegion region = self.mapView.region;
region.center = placemark.region.center;
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;

[self.mapView setRegion:region animated:YES];
[self.mapView addAnnotation:placemark];
}

];

用于注释标题和副标题,

CLPlacemark *topResult = [placemarks objectAtIndex:0];

// Create an MLPlacemark

MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

// Create an editable PointAnnotation, using placemark's coordinates, and set your own title/subtitle
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = placemark.coordinate;
point.title = @"Sample Location";
point.subtitle = @"Sample Subtitle";


// Set your region using placemark (not point)
MKCoordinateRegion region = self.mapView.region;
region.center = placemark.region.center;
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;

// Add point (not placemark) to the mapView
[self.mapView setRegion:region animated:YES];
[self.mapView addAnnotation:point];

// Select the PointAnnotation programatically
[self.mapView selectAnnotation:point animated:NO];

关于iphone - 您可以根据地址在 Mapview 中创建注释吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13557026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com