2017-03-09 28 views
0

iOSアプリでGoogle Mapsの画面にGMSMarkerを作成する必要があります。マーカーを画像の組み合わせ、つまり一般マーカー画像とユーザー画像にする必要があります。 例:Generic markerSwiftに組み合わされた画像でGMSMarkerを作成する方法

このマーカーの内側には、ユーザーの画像が収まる必要があります。私は私の資産の両方の画像を持っています。 試しました

しかし、これは不完全な画像を返しました。 代替ソリューションはありますか? 注:ここで提供されているマーカー画像の例は、私が実際に使用しているものではありません。これは長方形のマーカーです。

+0

あなたがしたいことがあり、ここで:https://developers.google.com/ maps/documentation/ios-sdk/marker – Pushp

答えて

1

ここで私はあなたにいくつかのサンプルコードを提供しています、それを試して、それはあなたの条件に応じて変更/ &カスタマイズに動作します:

let marker = GMSMarker() 
let lat = Double("13.063754") 
let long = Double("80.24358699999993") 
marker.position = CLLocationCoordinate2DMake(lat!,long!) 

///Creating UIView for Custom Marker 
let DynamicView=UIView(frame: CGRectMake(0, 0, 50, 50)) 
DynamicView.backgroundColor=UIColor.clearColor() 

//Creating Marker Pin imageview for Custom Marker 
var imageViewForPinMarker : UIImageView 
imageViewForPinMarker = UIImageView(frame:CGRectMake(0, 0, 40, 50)); 
imageViewForPinMarker.image = UIImage(named:"LocationPin") 

//Creating User Profile imageview 
var imageViewForUserProfile : UIImageView 
imageViewForUserProfile = UIImageView(frame:CGRectMake(0, 0, 35, 35)); 
imageViewForUserProfile.image = UIImage(named:"userprofile") 

//Adding userprofile imageview inside Marker Pin Imageview 
imageViewForPinMarker.addSubview(imageViewForUserProfile) 

//Adding Marker Pin Imageview isdie view for Custom Marker 
DynamicView.addSubview(imageViewForPinMarker) 

//Converting dynamic uiview to get the image/marker icon. 
UIGraphicsBeginImageContextWithOptions(DynamicView.frame.size, false, UIScreen.mainScreen().scale) 
DynamicView.layer.renderInContext(UIGraphicsGetCurrentContext()!) 
let imageConverted: UIImage = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext() 

marker.icon = imageConverted 
marker.map = self.mapView 
関連する問題