Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3539810

Browse files
committedFeb 18, 2013
GeoJSON Coordinate Formatter
1 parent cf2af22 commit 3539810

File tree

5 files changed

+104
-3
lines changed

5 files changed

+104
-3
lines changed
 

‎src/Location/Formatter/Coordinate/DMS.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Coordinate Formatter "DMS"
44
*
5-
* PHP version 5
5+
* PHP version 5.3
66
*
77
* @category Location
88
* @package Formatter

‎src/Location/Formatter/Coordinate/DecimalDegrees.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Coordinate Formatter "Decimal Degrees"
44
*
5-
* PHP version 5
5+
* PHP version 5.3
66
*
77
* @category Location
88
* @package Formatter

‎src/Location/Formatter/Coordinate/FormatterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Coordinate Formatter Interface
44
*
5-
* PHP version 5
5+
* PHP version 5.3
66
*
77
* @category Location
88
* @package Formatter
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* GeoJSON Coordinate Formatter
4+
*
5+
* PHP version 5.3
6+
*
7+
* @category Location
8+
* @package Formatter
9+
* @author Marcus T. Jaschen <mjaschen@gmail.com>
10+
* @copyright 2012 r03.org
11+
* @license http://www.opensource.org/licenses/mit-license MIT License
12+
* @link http://r03.org/
13+
*/
14+
15+
namespace Location\Formatter\Coordinate;
16+
17+
use Location\Coordinate;
18+
19+
/**
20+
* GeoJSON Coordinate Formatter
21+
*
22+
* @category Location
23+
* @package Formatter
24+
* @author Marcus T. Jaschen <mjaschen@gmail.com>
25+
* @license http://www.opensource.org/licenses/mit-license MIT License
26+
* @link http://r03.org/
27+
*/
28+
class GeoJSON implements FormatterInterface
29+
{
30+
/**
31+
* @param Coordinate $coordinate
32+
*
33+
* @return string
34+
*/
35+
public function format(Coordinate $coordinate)
36+
{
37+
return json_encode(
38+
array(
39+
'type' => 'point',
40+
'coordinates' => array(
41+
$coordinate->getLat(),
42+
$coordinate->getLng(),
43+
),
44+
)
45+
);
46+
}
47+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Location\Formatter\Coordinate;
4+
5+
use Location\Coordinate;
6+
7+
class GeoJSONTest extends \PHPUnit_Framework_TestCase
8+
{
9+
/**
10+
* @var DecimalDegrees
11+
*/
12+
protected $formatter;
13+
14+
/**
15+
* Sets up the fixture, for example, opens a network connection.
16+
* This method is called before a test is executed.
17+
*/
18+
protected function setUp()
19+
{
20+
$this->formatter = new GeoJSON;
21+
}
22+
23+
/**
24+
* Tears down the fixture, for example, closes a network connection.
25+
* This method is called after a test is executed.
26+
*/
27+
protected function tearDown()
28+
{
29+
}
30+
31+
/**
32+
* @covers Location\Formatter\DecimalDegrees::format
33+
*/
34+
public function testFormatDefault()
35+
{
36+
$coordinate = new Coordinate(52.5, 13.5);
37+
38+
$json = '{ "type" : "point" , "coordinates" : [ 52.5, 13.5 ] }';
39+
40+
$this->assertJsonStringEqualsJsonString($json, $this->formatter->format($coordinate));
41+
}
42+
43+
/**
44+
* @covers Location\Formatter\DecimalDegrees::format
45+
*/
46+
public function testFormatPrecision()
47+
{
48+
$coordinate = new Coordinate(52.123456789012345, 13.123456789012345);
49+
50+
$json = '{ "type" : "point" , "coordinates" : [ 52.123456789012345, 13.123456789012345 ] }';
51+
52+
$this->assertJsonStringEqualsJsonString($json, $this->formatter->format($coordinate));
53+
}
54+
}

0 commit comments

Comments
 (0)
Please sign in to comment.