【问题标题】:Show hotels (and near by places) by appropriate icon on Map in iPhone App在 iPhone 应用程序的地图上通过适当的图标显示酒店(和附近的地方)
【发布时间】:2012-01-31 06:05:06
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: iphone objective-c ios mapkit google-places-api


    【解决方案1】:

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

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

    -(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;
    }
    

    祝你好运……

    【讨论】:

    • 另外,通过这种解决方法,响应 Google Places API 附带的图标不会直接使用,正如您在代码中看到的那样。
    猜你喜欢
    • 2016-12-06
    • 1970-01-01
    • 2016-12-17
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 2019-01-18
    相关资源
    最近更新 更多