Save value geojson

1

How can I make a geojson to write numbers instead of string.

Example:

$geojson = array(
    'type'      => 'FeatureCollection',
    'features'  => array()
);

while( ($registo = mysqli_fetch_assoc($resultado)) !=null)
{
    $feature = array(
        'type' => 'Feature', 
        'geometry' => array(
            'type' => 'Point',
            'coordinates' => array($registo['x'], $registo['y'])
        ),
        'properties' => array(
            'id_publicidade' => $registo['id_publicidade'],
            'id_utilizador' => $registo['id_utilizador'],
            'nome' => $registo['nome'],
            'categoria' => $registo['categoria'],
        )
    );
array_push($geojson['features'], $feature);
};
echo json_encode($geojson);

My question is: 'coordinates' => array($registo['x'], $registo['y'])

When doing echo of json the result is: "coordinates":["-8.847618468261716","41.693271914384525"]

I do not want to quote the quotes, I want json to be without the chalk, because by continuing my code the chords can somehow interfere with the coordinates.

    
asked by anonymous 16.04.2015 / 22:10

1 answer

1

You can use floatval () that converts a string into a value with fractional part:

'coordinates' => array(floatval($registo['x']), floatval($registo['y']))
                          ^                        ^
    
16.04.2015 / 22:13