我的mapview工作正常,但是放在地图上的大头针的标题是美国。如何更改此标题?
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];发布于 2012-10-31 16:55:32
这是一个很老的问题,但也许其他人碰巧遇到了同样的问题(和我一样):
不要在地图的注解中添加MKPlacemark,而要使用MKPointAnnotation。此类的title和subtitle属性不是只读的。当您设置它们时,地图上的注释会相应地更新-这可能就是您想要的。
要在代码中使用MKPointAnnotation,请使用以下代码替换分配和添加MKPlacemark的行:
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属性。例如,如果正在运行异步地址查询,则可以在地址可用时立即将副标题设置为注释的地址。
发布于 2012-12-08 05:52:34
以下代码演示了在iOS 5.1中使用CLGeocoder在地图上放置注记
-(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];
}
}];
}发布于 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
https://stackoverflow.com/questions/7854209
复制相似问题