jmikola / geojson

GeoJSON implementation for PHP
MIT License
295 stars 47 forks source link

Adjusting constructor for multiple arguments #23

Closed bkuhl closed 2 years ago

bkuhl commented 8 years ago

The code in Point seems more complicated than necessary. It may be good to modify the constructor so that it's more clear how to structure data going into the class. For instance:

    public function __construct(
        $latitude,
        $longitude,
        CoordinateReferenceSystem $crs = null,
        BoundingBox $box = null
    ) {
        $this->coordinates = [
            $latitude,
            $longitude
        ];
jmikola commented 2 years ago

For context, this issue was originally reported against the 1.0.x branch. That code was heavily refactored in #33, which is now released as 1.1.0.

Changing the constructor signature to accept latitude and longitude separately would be a BC break and would also limit the ability to accept a third coordinate. Quoting the GeoJSON spec (RFC7946 3.1.1):

A position is an array of numbers. There MUST be two or more elements. The first two elements are longitude and latitude, or easting and northing, precisely in that order and using decimal numbers. Altitude or elevation MAY be included as an optional third element.

Since Point is also used by various other constructors (all of which accept coordinate n-tuples), I don't think this is something we could feasible change.