Как тиражировать карту Snapchat в Swift? - PullRequest
0 голосов
/ 05 апреля 2020

В последнее время я работаю над небольшим проектом. Я хотел бы скопировать программу Snapchat карту в Swift. В основном я хотел бы отобразить на карте значок, указывающий положение моего устройства, в котором установлена ​​программа. Я написал некоторый код на Swift, но я не очень доволен этим. Любой совет будет более чем признателен.

import Foundation
import CoreLocation
import MapKit

class DiscoverViewController : UIViewController, CLLocationManagerDelegate {

@IBOutlet weak var map: MKMapView!
let locationManager: CLLocationManager! = nil

override func viewDidLoad()
{
    super.viewDidLoad()

//for use in background
    self.locationManager.requestAlwaysAuthorization()

//for use in foreground
    self.locationManager.requestWhenInUseAuthorization()

    if (CLLocationManager.locationServicesEnabled())
    {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
    }
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: 
 [AnyObject]!) { var locValue:CLLocationCoordinate2D = manager.location.coordinate

    println("locations = \(localValue.latitude) \(localValue.longitude)")


    let center = CLLocationCoordinate2D(latitude: locValue.latitude, longitude: 
 locValue.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 
 0.01, longitudeDelta: 0.01))

    self.map.setRegion(region, animated: true)
    var currentLocation = CLLocation()

    var locationLat = currentLocation.coordinate.latitude
    var locationLong = currentLocation.coordinate.longitude
    println("locations = \(locationLat) \(locationLong) \ 
(currentLocation.coordinate.latitude) \(currentLocation.coordinate.longitude)")
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) { 
println("Errore while updating location" + error.localizedDescription)

}

func locationManagerDidPauseLocationUpdates(_ manager: CLLocationManager) {
    <#code#>
}
}
...