簡體   English   中英

如何在iOS中快速顯示多個標記的標記標題而不用點擊它,就像iOS中照片庫中的位置一樣

[英]how to display marker title for multiple markers without tapping on it in iOS swift like places in photo gallery in iOS

我無法顯示標記的信息窗口,但是在加載地圖時無需點擊標記就可以顯示信息嗎?

好的,由於Google地圖當前默認不提供此功能,因此可以解決此問題。 創建標記時,請按以下步驟進行操作:

  • 首先,您創建一個視圖並向其中添加標簽和圖像。

     UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)]; // Set label properties as required including marker Name UIImageView *markerIconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(35, 10, 30, 50)]; // Set image properties as required including image which will be displayed as marker UIView *markerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; [markerView addSubview:label]; [markerView addSubview:markerIconImageView]; 
  • 然后創建一個標記,並為其分配上方視圖的圖像:

     GMSMarker *marker = [[GMSMarker alloc] init]; marker.icon = [self imageWithView:markerView]; marker.position = coordinates for marker; marker.appearAnimation = kGMSMarkerAnimationPop; marker.map = your map; 
  • 供參考,這是我將視圖轉換為圖像的功能:

     -(UIImage *) imageWithView:(UIView *)view { UIGraphicsBeginImageContext(view.bounds.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } 

我們之所以將視圖轉換為圖像,是因為。 它占用較少的內存空間。

希望這可以幫助。 並為您提供了一種方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM