Skip to content

Commit

Permalink
Fix shortening code
Browse files Browse the repository at this point in the history
  • Loading branch information
ben221199 committed Sep 21, 2022
1 parent 6409730 commit 7693304
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/OpenLocationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public static function isPaddedByCode($code){
return (new self($code))->isPadded();
}

/**
* @param double $referenceLatitude
* @param double $referenceLongitude
* @return OpenLocationCode
*/
public function shorten($referenceLatitude,$referenceLongitude){
if(!$this->isFull()){
throw new InvalidArgumentException('shorten() method could only be called on a full code.');
Expand All @@ -234,8 +239,7 @@ public function shorten($referenceLatitude,$referenceLongitude){
}

$codeArea = $this->decode();
var_dump($codeArea);
$range = max(abs($referenceLatitude - $codeArea->getCenterLatitude()),$referenceLongitude - $codeArea->getCenterLongitude());
$range = max(abs($referenceLatitude - $codeArea->getCenterLatitude()),abs($referenceLongitude - $codeArea->getCenterLongitude()));

for($i=4;$i>=1;$i--){
if($range<(self::computeLatitudePrecision($i*2)*0.3)){
Expand Down
1 change: 0 additions & 1 deletion tests/ShorteningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function testShortening(){
if('B'!==$testData->testType && 'S'!==$testData->testType){
continue;
}
var_dump($testData);
$olc = new OpenLocationCode($testData->code);
$shortened = $olc->shorten($testData->referenceLatitude,$testData->referenceLongitude);
$this->assertEquals($testData->shortCode,$shortened->getCode(),'Wrong shortening of code '.$testData->code);
Expand Down

0 comments on commit 7693304

Please sign in to comment.