vendredi 23 décembre 2016

Laravel Radius of latitude & longitude

I am trying to find all postcodes within X radius of {lat}/{long}, however I am receiving a TypeError.

Error:

Type error: Argument 1 passed to App\Transformers\PostcodesTransformer::transform() 
must be an instance of App\Postcodes, instance of stdClass given, called in 
/home/vagrant/postcode-data/vendor/league/fractal/src/Scope.php on line 338

The query is:

$postcodes = DB::select("Select 
    id, 
    postcode, 
    latitude, 
    longitude, 
    district, 
    postal_town, 
    county, 
    country, 
    northing, 
    easting, 
    type,
    acos(sin(".$lat.")*sin(radians(latitude)) + cos(".$lat.")*cos(radians(latitude))*cos(radians(longitude)-".$lon.")) * ".$R." As distance
        From (
            Select *
            From uk_postcodes
            Where latitude Between ".$minLat." And ".$maxLat."
              And longitude Between ".$minLon." And ".$maxLon."
        ) As FirstCut
        Where acos(sin(".$lat.")*sin(radians(latitude)) + cos(".$lat.")*cos(radians(latitude))*cos(radians(longitude)-".$lon.")) * ".$R."< ".$rad."
        Order by distance");
    return $this->response->withCollection($postcodes, new PostcodesTransformer); 

However the result of the DB::select query returns stdClass.

How would I have it return an instance of the Postcodes class?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire