0

我正在使用 Google Places API 来获取预定义位置附近的地点。

它工作正常。我应该为每个地方显示 PushPins。现在,我为每个地方使用默认的红色图钉。

现在,我想为每个地方显示适当的图标,例如;适用于酒店、餐厅等......

在 android 上,我的同事开发人员通过使用 Google API 响应来做同样的事情。

在 iPhone 中,我找不到任何此类帮助。有没有办法在 iPhone 上做到这一点???

4

1 回答 1

2

这可能无法解决您的问题。但是,一些解决方法。

我遇到了类似的问题。我确实对数据进行了分类,并据此显示了符号以及条件。希望这段代码能让您了解我是如何做到的。

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{
    MKPinAnnotationView *view = nil;
    if (annotation != mapView.userLocation) {
        view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
        if (!view) {
            view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];
            CustomClassAnnotation *desclosureButton = [[CustomClassAnnotation alloc] initWithFrame:CGRectMake(0, 0, 29, 31)];
            [desclosureButton addTarget:self action:@selector(mapAction:) forControlEvents:(UIControlEventTouchUpInside)];
            view.rightCalloutAccessoryView = desclosureButton;
            view.canShowCallout = YES;
            }

        ((CustomClassAnnotation *)view.rightCalloutAccessoryView).annotation = annotation;

        if (((MapViewAnnotation *)annotation).type  == 1) {
            view.image = [UIImage imageNamed:@"image_type1.png"];  
        }
        else if (((MapViewAnnotation *)annotation).type == 2) {
            view.image = [UIImage imageNamed:@"image_type2.png"];
        }
        else if (((MapViewAnnotation *)annotation).type == 3) {
            view.image = [UIImage imageNamed:@"image_type3.png"];
        }
    }
    return view;
}

祝你好运...

于 2012-02-06T16:59:09.787 回答