Transport\Entity\Coordinate::createFromJson PHP Method

createFromJson() public static method

public static createFromJson ( $json )
    public static function createFromJson($json)
    {
        $coordinate = new self();
        $coordinate->type = 'WGS84';
        // best guess
        $x = self::intToFloat($json->x);
        $y = self::intToFloat($json->y);
        $coordinate = self::setHAFAScoordinates($coordinate, $x, $y);
        return $coordinate;
    }

Usage Example

示例#1
0
 /**
  * Factory method to create an instance and extract the data from the given JSON object
  *
  * @param   object     $json  The item JSON
  * @param   Location   $obj    An object or null to create it
  * @return  Location           The created instance
  */
 public static function createFromJson($json, Location $obj = null)
 {
     if (!is_object($obj)) {
         throw new \InvalidArgumentException('Argument must be an object');
     }
     if ($json->name) {
         $obj->name = html_entity_decode($json->name, null, 'UTF-8');
     }
     $obj->coordinate = Coordinate::createFromJson($json);
     return $obj;
 }