2012-01-31 125 views
0

我正在使用Google地方API獲取預定位置附近的地點。在iPhone應用程序的地圖上顯示酒店(並靠近地方)在地圖上的相應圖標

它工作正常。我應該爲每個地方顯示PushPins。現在,我爲每個地方使用默認的紅色圖釘。

現在,我想爲每個地方顯示適當的圖標,例如: 適用於酒店,餐廳等......

在android上,我的同事開發者通過使用Google API響應來做同樣的事情。

在iPhone中,我無法找到任何此類幫助。有沒有辦法在iPhone上做到這一點?

回答

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

祝你好運......

+0

此外,通過此解決,圖標自帶的迴應谷歌Places API的,是不能直接使用,因爲你可以在代碼中看到。 – Krishna 2012-02-06 17:01:02

相關問題