【发布时间】:2016-02-25 05:53:49
【问题描述】:
我有一本有 4-5 个位置的字典,虽然它可能会有所不同。需要在地图视图上显示所有这些位置并使用不同的图像。字典中有一个起始位置和其他位置。我已经为起点和终点。但并非所有位置都在地图上显示。以下是我尝试过的代码。
-(MKAnnotationView *)mapView:(MKMapView *)mapViewer viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *mapIdentifier=@"mapIdentifier";
MKAnnotationView *myAnnotation=[mapViewer dequeueReusableAnnotationViewWithIdentifier:mapIdentifier];
if (myAnnotation == nil) {
myAnnotation = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:mapIdentifier];
}
CLLocationCoordinate2D parkCllocation=CLLocationCoordinate2DMake([_tripDetails[@"park_lat"] doubleValue], [_tripDetails[@"park_long"] doubleValue]);
CLLocationCoordinate2D orginCllocation=CLLocationCoordinate2DMake([_tripDetails[@"origin_lat"] doubleValue], [_tripDetails[@"origin_long"] doubleValue]);
CLLocationCoordinate2D location=CLLocationCoordinate2DMake([loc[@"lat"] doubleValue], [loc[@"long"] doubleValue]);
if ((annotation.coordinate.latitude == parkCllocation.latitude)
&& (annotation.coordinate.longitude == parkCllocation.longitude))
{
myAnnotation.image=[UIImage imageNamed:@"pin1@2x.png"];
}
if ((annotation.coordinate.latitude == orginCllocation.latitude)
&& (annotation.coordinate.longitude == orginCllocation.longitude))
{
myAnnotation.image=[UIImage imageNamed:@"pin7@2x.png"];
}
if ((annotation.coordinate.latitude == location.latitude)
&& (annotation.coordinate.longitude == location.longitude))
{
myAnnotation.image=[UIImage imageNamed:@"pin4@2x.png"];
}
return myAnnotation
}
这是我从中获取位置的代码,在 loc dict 中,我存储了位置的 lat n long,然后将其添加到 cllocationcoordinate2D,当我在 viewforannotation 中添加这个 cllocationcoordinate2D 时,永远不会进入
if ((annotation.coordinate.latitude == location.latitude)
&& (annotation.coordinate.longitude == location.longitude))
条件。
请帮帮我,我陷入了困境。
【问题讨论】: