let latitude = (latArr.object(at: 0) as! NSString).doubleValue
let longitude = (longArr.object(at: 0) as! NSString).doubleValue
let camera = GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 12)
self.mapView.camera = camera
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
for (index, _) in latArr.enumerated() {
let latitude = (latArr.object(at: index) as! NSString).doubleValue
let longitude = (longArr.object(at: index) as! NSString).doubleValue
state_marker.position = CLLocationCoordinate2D(latitude: latitude , longitude:longitude)
let userType = UserDefaults.standard.value(forKey:"usertype") as! NSString
state_marker.title = (AddreesArr.object(at: index) as! String)
state_marker.snippet = (AddreesArr.object(at: index) as! String)
state_marker.icon = createImage((AddreesArr.object(at: index) as! String) , "marker_orange")
}
state_marker.map = mapView
func createImage(_ name: String , _ imageName : String) -> UIImage {
//count is the integer that has to be shown on the marker
let color = UIColor.white
// select needed color
let string = "\(name)"
// the string to colorize
let attrs = [NSAttributedString.Key.foregroundColor: color]
let attrStr = NSAttributedString(string: string, attributes: attrs)
// add Font according to your need
let userType = UserDefaults.standard.value(forKey:"usertype") as! NSString
if userType == "1"
{
let image = UIImage(named:imageName)!
UIGraphicsBeginImageContext(image.size)
image.draw(in: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(image.size.width), height: CGFloat(image.size.height)))
let rect = CGRect(x: CGFloat(5), y: CGFloat(5), width: CGFloat(image.size.width), height: CGFloat(image.size.height))
attrStr.draw(in: rect)
}
else
{
let image = UIImage(named: imageName)!
UIGraphicsBeginImageContext(image.size)
image.draw(in: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(image.size.width), height: CGFloat(image.size.height)))
let rect = CGRect(x: CGFloat(5), y: CGFloat(5), width: CGFloat(image.size.width), height: CGFloat(image.size.height))
attrStr.draw(in: rect)
}
// The image on which text has to be added
let markerImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return markerImage
}
Comments
Post a Comment