Skip to content

Instantly share code, notes, and snippets.

@dbabbs
Last active June 27, 2018 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbabbs/ce30f8c4f2432d7fc7d3fe42aae15ed8 to your computer and use it in GitHub Desktop.
Save dbabbs/ce30f8c4f2432d7fc7d3fe42aae15ed8 to your computer and use it in GitHub Desktop.
import UIKit
import SCSDKCreativeKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
if CLLocationManager.authorizationStatus() == .notDetermined {
locationManager.requestWhenInUseAuthorization()
}
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.startUpdatingLocation()
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 150, height: 50))
button.setTitle("Send to Snapchat", for: .normal)
button.setTitleColor(self.view.tintColor, for: .normal)
self.view.addSubview(button)
button.center = self.view.center
button.addTarget(self, action: #selector(self.send), for: .touchUpInside)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
}
@objc func send() {
let img = createMapImage()
let sticker = SCSDKSnapSticker(stickerImage: img)
let snap = SCSDKNoSnapContent()
snap.sticker = sticker
snap.attachmentUrl = "https://developer.here.com"
let api = SCSDKSnapAPI(content: snap)
api.startSnapping { (error) in }
}
func createMapImage() -> UIImage {
struct here {
static var id = "YOUR-HERE-ID"
static var code = "YOUR-HERE-CODE"
}
let lat = locationManager.location!.coordinate.latitude
let long = locationManager.location!.coordinate.longitude
//Map Image API parameters
let zoom = 14 //Zoom level
let quality = 100 //Image quality
let markerType = 1 //Marker type
let mapStyle = 5 //Map style, currently set to normal day grey
let endpoint = URL(string: "https://image.maps.api.here.com/mia/1.6/mapview?app_id=\(here.id)&app_code=\(here.code)&poi=\(lat),\(long)&z=\(zoom)&q=\(quality)&poithm=\(markerType)&t=\(mapStyle)")
let response = try? Data(contentsOf: endpoint!)
let mapImage = UIImage(data: response!)
return mapImage!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment