Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在Swift中使用组合图像创建GMSMarker_Ios_Swift_Google Maps - Fatal编程技术网

Ios 如何在Swift中使用组合图像创建GMSMarker

Ios 如何在Swift中使用组合图像创建GMSMarker,ios,swift,google-maps,Ios,Swift,Google Maps,我需要在iOS应用程序中为我的谷歌地图屏幕创建一个GMSMarker。我需要标记是图像的组合,即通用标记图像和用户图像。 例如: 在这个标记中,我需要适合用户的图像。我的资产中有两个图像。 它试过了 但这返回了一个不完美的图像。 有其他解决办法吗? 注意:这里提供的示例标记图像不是我实际使用的图像。这是一个矩形标记。这里我为您提供了一些示例代码,您可以尝试一下,它将根据您的需求进行定制/修改: let marker = GMSMarker() let lat = Double("13.06375

我需要在iOS应用程序中为我的谷歌地图屏幕创建一个
GMSMarker
。我需要标记是图像的组合,即通用标记图像和用户图像。 例如:

在这个标记中,我需要适合用户的图像。我的资产中有两个图像。 它试过了

但这返回了一个不完美的图像。 有其他解决办法吗?
注意:这里提供的示例标记图像不是我实际使用的图像。这是一个矩形标记。

这里我为您提供了一些示例代码,您可以尝试一下,它将根据您的需求进行定制/修改:

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
您想要的是:
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