首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKPlacemark引脚标题

MKPlacemark引脚标题
EN

Stack Overflow用户
提问于 2011-10-22 03:14:31
回答 3查看 6.9K关注 0票数 12

我的mapview工作正常,但是放在地图上的大头针的标题是美国。如何更改此标题?

代码语言:javascript
复制
    MKCoordinateRegion thisRegion = {{0.0,0.0}, {0.0,0.0}};

        thisRegion.center.latitude = 22.569722;
        thisRegion.center.longitude = 88.369722;

        CLLocationCoordinate2D coordinate;
        coordinate.latitude = 22.569722;
        coordinate.longitude = 88.369722;

        thisRegion.center = coordinate;

        MKPlacemark *mPlacemark = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];

        [mapView addAnnotation:mPlacemark];
        [mapView setRegion:thisRegion animated:YES];
EN

回答 3

Stack Overflow用户

发布于 2012-10-31 16:55:32

这是一个很老的问题,但也许其他人碰巧遇到了同样的问题(和我一样):

不要在地图的注解中添加MKPlacemark,而要使用MKPointAnnotation。此类的title和subtitle属性不是只读的。当您设置它们时,地图上的注释会相应地更新-这可能就是您想要的。

要在代码中使用MKPointAnnotation,请使用以下代码替换分配和添加MKPlacemark的行:

代码语言:javascript
复制
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = coordinate;
annotation.title = NSLocalizedString(@"Dropped Pin",
                                     @"Title of a dropped pin in a map");
[mapView addAnnotation:annotation];

您也可以在以后的任何时候设置title和subtitle属性。例如,如果正在运行异步地址查询,则可以在地址可用时立即将副标题设置为注释的地址。

票数 15
EN

Stack Overflow用户

发布于 2012-12-08 05:52:34

以下代码演示了在iOS 5.1中使用CLGeocoder在地图上放置注记

代码语言:javascript
复制
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

// Apple recommendation - if location is older than 30s ignore
// Comment out below during development
/*  if (fabs([newLocation.timestamp timeIntervalSinceDate:[NSDate date]]) > 30) {
    NSLog(@"timestamp");
    return;
}*/   

CLLocation *coord = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];                            
[geocoder reverseGeocodeLocation:coord completionHandler:^(NSArray *placemarks, NSError *error) {

    if (error) {
        NSLog(@"Geocode failed with error");
    }

    // check for returned placemarks
    if (placemarks && placemarks.count > 0) {
        CLPlacemark *topresult = [placemarks objectAtIndex:0];
        MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
        annotation.coordinate = locationManager.location.coordinate;
        annotation.title = NSLocalizedString(@"You are here", @"Title");
        annotation.subtitle = [NSString stringWithFormat:@"%@, %@", [topresult subAdministrativeArea], [topresult locality]];
        [self.mapView addAnnotation:annotation];
    }
}];
}
票数 5
EN

Stack Overflow用户

发布于 2011-10-22 03:25:23

查看MKPlacemark所遵循的MKAnnotation协议。您应该能够设置标题。

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotation_Protocol/Reference/Reference.html

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKPlacemark_Class/Reference/Reference.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7854209

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档