地图视图注释调整
大家好,当用户输入以下代码时,我正在尝试更改注释图像
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
for (int i = 0; i < [_annotationArray count]; i++)
{
//MKAnnotation xxx = [_annotationArray objectAtIndex:i];
Shadows* shadowObj2 = [_shadowArray objectAtIndex:i];
NSLog(@"%@",_shadowArray);
CLLocationCoordinate2D location3;
location3.latitude = [shadowObj2.position_x floatValue];
location3.longitude = [shadowObj2.position_y floatValue];
CLLocation* locationold = [[CLLocation alloc] initWithLatitude:location3.latitude longitude:location3.longitude];
CLLocationDistance kilometers = [newLocation distanceFromLocation:locationold];
//temp = [kilometers intValue];
if (kilometers > 50 && kilometers <100)
{
MKAnnotationView* newA = [[MKAnnotationView alloc] initWithAnnotation:[_annotationArray objectAtIndex:i] reuseIdentifier:@"annotation1"];
newA.image = [UIImage imageNamed:@"shadowS.png"];
newA.canShowCallout = YES;
}
[locationold release];
//[shadowObj2 release];
}
}
,但我无法更改注释图像,请告诉我为什么我无法做到这一点
HI all i am trying to change the image of annotation when user walk in following code
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
for (int i = 0; i < [_annotationArray count]; i++)
{
//MKAnnotation xxx = [_annotationArray objectAtIndex:i];
Shadows* shadowObj2 = [_shadowArray objectAtIndex:i];
NSLog(@"%@",_shadowArray);
CLLocationCoordinate2D location3;
location3.latitude = [shadowObj2.position_x floatValue];
location3.longitude = [shadowObj2.position_y floatValue];
CLLocation* locationold = [[CLLocation alloc] initWithLatitude:location3.latitude longitude:location3.longitude];
CLLocationDistance kilometers = [newLocation distanceFromLocation:locationold];
//temp = [kilometers intValue];
if (kilometers > 50 && kilometers <100)
{
MKAnnotationView* newA = [[MKAnnotationView alloc] initWithAnnotation:[_annotationArray objectAtIndex:i] reuseIdentifier:@"annotation1"];
newA.image = [UIImage imageNamed:@"shadowS.png"];
newA.canShowCallout = YES;
}
[locationold release];
//[shadowObj2 release];
}
}
But i am unable to change annotation image please tell me why i am not able to do it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以按照教程
http 进行自定义注释://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/
You can make your custom annotation follow the tutorial
http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/
我不认为这段代码与地图视图有任何联系,并且您正在使用新图像分配 MKAnnotationView 的新实例。这不会改变地图上已有的现有内容。您需要做的是检查地图视图视图中的注释距离,然后更改其图像。
I don't think this code has any connection with the map view and u are allocating a new instance of MKAnnotationView with the new image. This doesn't change the existing ones which you already have on the map. What you need to do is check the distance in mapview's view for annotation and then change its image there.