2013-04-17 131 views
13

我正在使用故事板和Google地圖構建iOS應用程序。使用iOS6的從Google地圖中刪除標記iOS

我的應用程序的功能,如Facebook的應用程序看到

在我的左視圖,我在其中有緯度/經度線列表中選擇一個項目,並將其顯示在我的地圖上按照拆分視圖導航方法

- (void)viewWillAppear:(BOOL)animated

我想刪除此方法的所有標記之前我再加一條(所以只有一個標記在地圖上),有沒有辦法做到這一點?下面是我的代碼標記提前添加到的MapView

謝謝 - 喬恩

- (void)loadView 
{ 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:poi.lat 
                  longitude:poi.lon 
                   zoom:15]; 
    mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

    mapView.myLocationEnabled = YES; 
    self.view = mapView; 
    mapView.mapType = kGMSTypeHybrid; 

    //Allows you to tap a marker and have camera pan to it 
    mapView.delegate = self; 
} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init]; 
    options.position = CLLocationCoordinate2DMake(poi.lat, poi.lon); 
    options.title = poi.title; 
    options.snippet = poi.description; 
    options.icon = [UIImage imageNamed:@"flag-red.png"]; 
    [mapView addMarkerWithOptions:options]; 

    [mapView animateToLocation:options.position]; 
    [mapView animateToBearing:0]; 
    [mapView animateToViewingAngle:0]; 
} 

回答

7

請參閱谷歌地圖文檔:Google Maps SDK for iOS

請參閱部分標題爲「刪除標記」。總是檢查這些方法的文件。

+0

我正在使用GMSMapView - Google maps Class。除非你可以將這些方法應用到谷歌地圖? – jchri853

+0

我的歉意,請參閱編輯。 – iOSGuru248

+0

哈哈NP,在文檔中錯過了,感謝您花時間幫助我! – jchri853

27

要刪除所有標記簡單做:

[self.mapView clear]; 
+0

如何刪除特定標記? –

+0

這個刪除標記和所有項目的地圖,更好的解決方案? –

+0

請注意,這將清除地圖上的所有內容。所以如果你有標記和多邊形,它也會清除它們。如果你喜歡這兩個,你會想把所有的標記放在一個數組中,循環遍歷數組並清除每一個。這將保持你的多段線。 –

26

要刪除所有標記

mapView.clear() 

要刪除特定的標記

myMarker.map = nil 
0

mapView.clear()

//它w生病清除GMSMapView中的所有標記。