Создавать объект типа CLLocation (Swift) [duplicate]

Самое простое решение - создать функцию JavaScript и вызвать его для обратного вызова Ajax success.

function callServerAsync(){
    $.ajax({
        url: '...',
        success: function(response) {

            successCallback(response);
        }
    });
}

function successCallback(responseObj){
    // Do something like read the response and show data
    alert(JSON.stringify(responseObj)); // Only applicable to JSON response
}

function foo(callback) {

    $.ajax({
        url: '...',
        success: function(response) {
           return callback(null, response);
        }
    });
}

var result = foo(function(err, result){
          if (!err)
           console.log(result);    
}); 
17
задан Christopher Wade Cantley 11 November 2014 в 19:22
поделиться

1 ответ

Выяснил это.

Когда mapView изменяет область, получите Lat и Lon из CLLocationCoordinate2D и создайте переменную CLLocation с переданными лат и lon.

func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool){

    var centre = mapView.centerCoordinate as CLLocationCoordinate2D

    var getLat: CLLocationDegrees = centre.latitude
    var getLon: CLLocationDegrees = centre.longitude


    var getMovedMapCenter: CLLocation =  CLLocation(latitude: getLat, longitude: getLon)

    self.lastLocation = getMovedMapCenter
    self.fetchCafesAroundLocation(getMovedMapCenter)

}
34
ответ дан Christopher Wade Cantley 26 August 2018 в 09:36
поделиться
Другие вопросы по тегам:

Похожие вопросы: